-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
55 lines (48 loc) · 2.3 KB
/
utils.cpp
File metadata and controls
55 lines (48 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// utils.cpp
// AlgoFISE1
//
// Created by Christophe Gravier on 12/09/16.
// Copyright © 2016 Christophe Gravier. All rights reserved.
//
#include "utils.h"
long random_at_most(long max) {
unsigned long
// max <= RAND_MAX < ULONG_MAX, so this is okay.
num_bins = (unsigned long) max + 1,
num_rand = (unsigned long) RAND_MAX + 1,
bin_size = num_rand / num_bins,
defect = num_rand % num_bins;
long x;
do {
x = rand();
}
// This is carefully written not to overflow
while (num_rand - defect <= (unsigned long)x);
// Truncated division is intentional
return x/bin_size;
}
float getEfficiency(int typeAttaque, int typeDefense) {
static float typeChart[18][18] = {
{1, 1, 1, 1, 1, 0.5, 1, 0, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1}, // Normal
{2, 1, 0.5, 0.5, 1, 2, 0.5, 0, 2, 1, 1, 1, 1, 0.5, 2, 1, 2, 0.5}, // Fighting
{1, 2, 1, 1, 1, 0.5, 2, 1, 0.5, 1, 1, 2, 0.5, 1, 1, 1, 1, 1}, // Flying
{1, 1, 1, 0.5, 0.5, 0.5, 1, 0.5, 0, 1, 2, 1, 1, 1, 1, 1, 1, 2}, // Poison
{1, 1, 0, 2, 1, 2, 0.5, 1, 2, 2, 1, 0.5, 2, 1, 1, 1, 1, 1}, // Ground
{1, 0.5, 2, 1, 0.5, 1, 2, 1, 0.5, 2, 1, 1, 1, 1, 2, 1, 1, 1}, // Rock
{1, 0.5, 0.5, 0.5, 1, 1, 1, 0.5, 0.5, 0.5, 2, 1, 2, 1, 1, 1, 2, 0.5}, // Bug
{0, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 0.5, 1}, // Ghost
{1, 1, 1, 1, 1, 2, 1, 1, 0.5, 0.5, 0.5, 1, 0.5, 1, 2, 1, 1, 2}, // Steel
{1, 1, 1, 1, 1, 0.5, 2, 1, 2, 0.5, 2, 0.5, 1, 1, 2, 0.5, 1, 1}, // Fire
{1, 1, 0.5, 0.5, 2, 2, 0.5, 1, 0.5, 0.5, 0.5, 2, 0.5, 1, 0.5, 1, 1, 1}, // Grass
{1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 0.5, 0.5, 1, 1, 1, 0.5, 1, 1}, // Water
{1, 1, 2, 1, 0, 1, 1, 1, 1, 1, 0.5, 2, 0.5, 1, 1, 0.5, 1, 1}, // Electric
{1, 2, 1, 2, 1, 1, 1, 1, 0.5, 1, 1, 1, 1, 0.5, 1, 1, 0, 1}, // Psychic
{1, 1, 2, 1, 2, 1, 1, 1, 0.5, 0.5, 2, 0.5, 1, 1, 0.5, 2, 1, 1}, // Ice
{1, 1, 1, 1, 1, 1, 1, 1, 0.5, 1, 1, 1, 1, 1, 1, 2, 1, 0}, // Dragon
{1, 0.5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 0.5, 0.5}, // Dark
{1, 2, 1, 0.5, 1, 1, 1, 1, 0.5, 0.5, 1, 1, 1, 1, 1, 2, 2, 1} // Fairy
};
if(typeAttaque < 0 || typeAttaque > 17 || typeDefense < 0 || typeDefense > 17) return 1.0;
return typeChart[typeAttaque][typeDefense];
}