public Decision(underDecision dec, ChessMan piece) { chess = piece; decision = dec; }
public Decision Evaluate(ChessMan chess, Case [,] board) { int x = chess.position.x; int y = chess.position.y; List <Case> possibleCase = chess.GetPossibleMovement(board); List <underDecision> underDecs = new List <underDecision>(); int initialsMoves = GetListOfPossibleMove(chess.color).Count; EchecThreat isThreatened = PieceEchec(board, chess); foreach (Case c in possibleCase) { underDecision d = new underDecision(0, c); //here we found out that we can get a special piece with a priority, but take care, it might put us in a bad situation if (c.currPiece != null && c.currPiece.color != chess.color) { d.value += c.currPiece.Priority; d.SetReason("getting piece with priority : " + c.currPiece.Priority); } //that's a bad decision and even more, an unaceptable move since its our own piece, dont even listen to this else if (c.currPiece != null) { continue; } //create a simulation that we will simulate later on Simulation s = new Simulation(board[x, y], c); //i am already in echec if (isThreatened != null) { //simulate, so we can check if i can find some good situations //this move can send me out of echec, we should consider it if (PieceEchec(board, s) == null) { d.value += chess.Priority; d.SetReason("getting out of echec add : " + chess.Priority); Debug.Log(chess.ToString() + " not getting out of echec ??" + d.value); } //this move cant get me ouf of echec, we delete some priority to it, but it might be usefull on a certain sutaiton else { d.value -= chess.Priority; d.SetReason("cant get out, del : " + chess.Priority); } } else { //i was not in an echec move but im going into it? remove some value to this move if (PieceEchec(board, s) != null) { d.value -= chess.Priority; d.SetReason("going in echec intentionnaly del : " + chess.Priority); } } //get all of the move that come from our team after the simulation List <Case> moves = GetListOfPossibleMove(chess.color); bool covered = false; foreach (Case cover in moves) { if (cover == c) { covered = true; } } // calculate how many moves we opened up by doing this (because it means we have more possible movements out of this int difference = (moves.Count - initialsMoves) / 2; d.value += difference; d.SetReason("add some cases to play" + difference); if (StaticClass.m_sTools.GetPossibleMove(!chess.color) <= 0) { d.value += 1000; d.SetReason("put ennemy in mat"); } //now found out if we can put ennemy pieces in echec out of this move List <Case> SimulatedMove = chess.GetPossibleMovement(m_sCase.setupBoard.board, false); foreach (Case simulatedCase in SimulatedMove) { EchecThreat simulatedThreat = PieceEchec(board, simulatedCase.currPiece); if (simulatedCase.currPiece != null && simulatedCase.currPiece.color != chess.color) { //we can actually put a piece in echec out of this, that's pretty good, even more if we are covered by another piece d.value += simulatedCase.currPiece.Priority / (covered == true ? 2 : 10); d.SetReason("put an piece in echec : " + (simulatedCase.currPiece.Priority / (covered == true ? 2 : 10))); } //if we can cover an ally piece that is in echec do it else if (simulatedCase.currPiece != null && simulatedThreat != null) { d.value += simulatedCase.currPiece.Priority / 2; d.SetReason("helped a piece in echec : " + simulatedCase.currPiece.Priority / 2); } } s.Delete(); underDecs.Add(d); } underDecision bestUdec = null; foreach (underDecision d in underDecs) { if (bestUdec == null) { bestUdec = d; } else if (bestUdec.value < d.value) { bestUdec = d; } else if (bestUdec.value == d.value) { if (Random.Range(0, 2) == 1) { bestUdec = d; } } } return(new Decision(bestUdec, chess)); }