forked from cbermudez97/proyecto-declarativa-I
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.pl
107 lines (101 loc) · 3.01 KB
/
game.pl
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
99
100
101
102
103
104
105
106
107
:-[
"Azul/player_logic.pl"
].
% Check if bag needs to be refiled
checkBag :-
bag([_|_]),
!.
checkBag :-
bag([]),
discarted(Discarted),
retract(bag([])),
assert(bag(Discarted)),
buildDiscarted,
!.
% Update next round first player
checkEspecial(_, no) :-
!.
checkEspecial(PlayerId, si) :-
dropEspecial(PlayerId, si),
format("El jugador ~a tomo la ficha especial y sera el primero en la siguiente Ronda.~n",[PlayerId]),
update_first(PlayerId),
!.
% Start players rotations making all moves possible
startPlayerRotation(_) :- % No more possible moves
getAllMoves([]),
center([]),
format("No se pueden realizar jugadas.~n",[]),
!.
startPlayerRotation(_) :- % Weird Case
getAllMoves([]),
center([especial]),
actual_player(PlayerId),
checkEspecial(PlayerId, si),
format("No se pueden realizar jugadas.~n",[]),
!.
startPlayerRotation(CantPlayers) :-
actual_player(PlayerId),
format("Turno del Jugador ~a.~n",[PlayerId]),
format("Estado de la Mesa:~n", _),
print_factories,
print_center,
playerMove(PlayerId, Move, Especial),
Move,
checkEspecial(PlayerId, Especial),
format("Fin del Turno.~n",[]),
rotate_actual(CantPlayers),
startPlayerRotation(CantPlayers),
!.
% Number of Factories with N players
toBuildFacts(2, 5).
toBuildFacts(3, 7).
toBuildFacts(4, 9).
% Start Azul Round with N players
startAzulRound(_) :- % Someone have a row in the wall completed
findall(
PlayerId,
(
player(PlayerId,_,_,_,_,_,_,_,Wall),
member(Row, [1,2,3,4,5]),
getRow(Row, Wall, RowData),
length(RowData, 5)
),
Enders
),
length(Enders, Len),
Len =\= 0,
Enders=[First|_],
format("El juego termina pues el jugador ~a ha completado una fila.~n", [First]),
!.
startAzulRound(_) :- % The bag is empty so no more rounds are posible
bag([]),
format("El juego termina pues se han acabado las fichas.~n", _),
!.
startAzulRound(CantPlayers) :-
format("Empezando Nueva Ronda:~n",_),
first_player(RoundFirst), % Set round first player
update_actual(RoundFirst),
toBuildFacts(CantPlayers, CantFacts), % Build Factories
notrace(buildFacts(CantFacts)),
startPlayerRotation(CantPlayers), % All players make all moves
format("Fin de la Ronda.~n",[]),
format("Preparando Siguiente Ronda.~n",[]),
findall(_, (player(PlayerId,_,_,_,_,_,_,_,_), playerRoundEnd(PlayerId)), _), % Update players board
checkBag,
buildCenter, % Reset Center
format("Fin de la Preparación.~n",[]),
startAzulRound(CantPlayers), % Play next round
!.
% Start Azul Game with N players
startAzulGame(CantPlayers) :-
format("Empezando juego de Azul con ~a jugadores!~n", [CantPlayers]),
erase_players,
createPlayers(CantPlayers),
update_first(1), % Always player 1 starts
buildBag(_),
buildCenter,
buildDiscarted,
startAzulRound(CantPlayers),
format("Resultados:~n", _),
print_scores,
!.