-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdomino.c
66 lines (45 loc) · 1.51 KB
/
domino.c
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
#include "lista.h"
#include <stdio.h>
#define PIECE_MAX 7
//deck_player
//deck_pc
//deck_table
//deck_back
TppecaDomino * ai_move(TppecaDomino * deck_pc, TppecaDomino * deck_player, TppecaDomino ** deck_table, TppecaDomino ** deck_back){
TppecaDomino * p;
int i;
int bool1, bool2;
TppecaDomino * unknown = sum(deck_player, *deck_back);
int * freq_order = frequency_rank(unknown);
free(unknown);
unknown = NULL;
for(i = 0; i < PIECE_MAX; i++){
for(p = deck_pc; p != NULL; p = p->right){
bool1 = (int)p->numberRight == freq_order[i] &&
(*deck_table == NULL || p->numberLeft == left_table_number(*deck_table) || p->numberLeft == right_table_number(*deck_table));
bool2 = (int)p->numberLeft == freq_order[i] &&
(*deck_table == NULL || p->numberRight == left_table_number(*deck_table) || p->numberRight == right_table_number(*deck_table));
if(bool1 || bool2){
deck_pc = push_table(deck_pc, deck_table, p->numberRight, p->numberLeft);
return deck_pc;
}
}
if(i == PIECE_MAX - 1 && *deck_back != NULL){
deck_pc = catch_piece(deck_pc, deck_back);//pesca uma peça
unknown = sum(deck_player, *deck_back);
freq_order = frequency_rank(unknown);
free(unknown);
unknown = NULL;
i = -1;//para reiniciar o loop
}
}
return deck_pc;
}
int can_play(TppecaDomino * deck_a, TppecaDomino * deck_table, TppecaDomino * deck_back){
TppecaDomino * p;
//if(deck_back != NULL) return 1;
for(p = deck_a; p != NULL; p = p->right){
if(where_play(p, deck_table)) return 1;
}
return 0;
}