Example #1
0
    private int EvaluateGameState()
    {
        int whitePlayerScore = 0;
        int blackPlayerScore = 0;

        foreach (Piece piece in cgs.GetPieces(boardCopy))
        {
            if (piece.GetTeam() == ChessGlobals.Teams.BLACK_TEAM)
            {
                blackPlayerScore += GetScoreForPieceType(piece);
                blackPlayerScore += GetScoreForPiecePosition(piece.GetPiecePosition());
            }
            else if (piece.GetTeam() == ChessGlobals.Teams.WHITE_TEAM)
            {
                whitePlayerScore += GetScoreForPieceType(piece);
                whitePlayerScore += GetScoreForPiecePosition(piece.GetPiecePosition());
            }
            else
            {
                Debug.Log("Illegal team color evaluateGameState()");
            }
        }
        ChessGlobals.GameState gameState = cgs.GetGameState();
        if (gameState.getState() == ChessGlobals.GameState.BLACK_TURN)
        {
            return(blackPlayerScore - whitePlayerScore);
        }
        else if (gameState.getState() == ChessGlobals.GameState.WHITE_TURN)
        {
            return(whitePlayerScore - blackPlayerScore);
        }
        else if (gameState.getState() == ChessGlobals.GameState.WHITE_WIN || gameState.getState() == ChessGlobals.GameState.BLACK_WIN || gameState.getState() == ChessGlobals.GameState.DRAW)
        {
            return(Int32.MinValue + 1);
        }
        Debug.Log("Illegal game state in evaluateGameState()");
        return(0);
    }
Example #2
0
 // Update is called once per frame
 protected virtual void Update()
 {
     //handles moving a piece
     if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && movePieceFrom != Vector3.down)
     {
         //here must disallow moving pieces to anywhere other than a legal square
         if (legalMovesForAPiece != null)
         {
             movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition;
             DrawPiece.ClearHighlight();
             if (board.IsOccupied(movePieceTo))
             {
                 //if the color of the piece matches the current turn
                 if (board.GetPieceAt(movePieceTo).GetTeam() == gameState.getState())
                 {
                     movePieceTo   = Vector3.down;
                     movePieceFrom = Vector3.down;
                     drawBoard.ClearHighlights();
                     return;
                 }
             }
             else
             {
                 drawBoard.ClearHighlights();
             }
             if (!legalMovesForAPiece.Contains(movePieceTo))
             {
                 movePieceTo            = Vector3.down;
                 currentlySelectedPiece = null;
             }
         }
     }
     //handles clicking a piece
     else if (DrawPiece.IsClicked)
     {
         SelectPiece();
     }
     // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose.
     // In the real game we would also have to check if it is a valid move.
     if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down)
     {
         MovePieceModel(movePieceFrom, movePieceTo);
     }
 }