/**
@descr returns true if the current player is dead
@form  taoIsDead
*/
taoIsDead :- 
	currentPlayer(ID),
	taoist(ID,_,_,0,_,_),
	!.

/**
	@descr there are no cards left
	@form  everybodyLost.
*/
gameOver :-
	cards([]),
	broadcastGameOver(lost),
	!.

/**
	@descr There is no player alive.
	@form everybodyLost.
*/
gameOver :-
	forall(taoist(_,_,_,Qi,_,_), Qi =< 0),
	broadcastGameOver(lost),
	!.

/**
@descr 3 ghostFields are haunted taoists lost
@form everybodyLost
*/


gameOver :-
	findall(TileID,
		village(TileID,_,_,haunted,_),
		HauntedVillages),	
	length(HauntedVillages,Sum),
	Sum >= 3,
	broadcastGameOver(lost),
	!.

/**
@descr wu-feng is defeated and there is min. one taoist alife.
@form  win.
*/

gameOver :-
	cards(Cards),
	length(Cards,CardsCount),
	CardsCount =< 10,
	not(wuFengAlive),
	broadcastGameOver(win).
	
wuFengAlive :-
	ghostField(_,GhostID,_),
	GhostID >= 56,
	GhostID =< 65.
