-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
98 lines (88 loc) · 2.63 KB
/
Source.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<iostream>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include <sstream>
#include "Move.h"
#include "Board.h"
#include "Bag.h"
#include "Player.h"
#include "Tie.h"
#include <time.h>
using namespace std;
# define depth 10
# define S 10
///implement for omnia
double huristicBoard(const Board &board) {
return 0;
}
/// implement for ghada and walaa
Move huristicMoves(Board board,Player ana,Player opponent) {
Move m;
return m;
}
// implement for riham
int applyMove(const Move & move, Board & board,Player & p ) {
int score = 0;
return score;
}
double radom_rack(Bag & bag, Player & opponent) {
double p = 1.0;
srand(time(NULL));
int tot = bag.bagLen();
while (opponent.getTotalTies() < 7 && tot) {////// for omnia
bool x = false;
int r = rand() % 27;
while (!bag.getTieCount(r)) {//// for omnia
r = rand() % 27;
}
p = p * bag.getTieCount(r) * 1.0 / tot;/////for omnia
bag.removeTie(r);
tot--;
opponent.addTie(r);
}
return p;
}
double ProbabilisticSearch(int idx,Board & board,bool game,Player ana,Player opponent,Bag & bag) {
if (board.tiesCount()>=100 || idx >= depth) {////////
return huristicBoard(board);
// mfrod azod 7aga hna huristic of board
}
double ret = 0;
for (int i = 0; i < S; ++i) {
double p;
if (game == 1) {
p = radom_rack(bag, opponent);
Move move = huristicMoves(board, opponent, ana);
int score = applyMove(move, board, opponent);
ret -= p * ProbabilisticSearch(idx + 1, board, 0,
ana, opponent, bag
) + score;
} else {
p = radom_rack(bag, ana);
Move move = huristicMoves(board, ana, opponent);
int score = applyMove(move, board, ana);
ret += p * ProbabilisticSearch(idx + 1, board, 1,
ana, opponent, bag
) + score;
}
}
return ret;
}
// ana mb3otly acctions klaha tnf3 tt3ml rihaaaaaaaaaaaaaaaaaam
Move nextPlay(const vector<Move>&plays, Board board, Bag bag , Player ana ) {
double mx = -1e9;
int playIdx = 0;
int size = plays.size();
for (int i = 0; i < plays.size(); ++i) {
int score=applyMove(plays[i], board, ana);
Player opponent(2);/////for omnia
double expectedValue = ProbabilisticSearch(0, board, 1, ana, opponent, bag)+score/1.0/size;
if (mx < expectedValue) {
mx=expectedValue;
playIdx = i;
}
}
return plays[playIdx];
}