コード例 #1
0
    // Use this for initialization
    protected virtual void Start()
    {
        legalMovesForAPiece = new List <Vector2>();
        gameState           = new GameState(ChessGlobals.GameState.WHITE_TURN);

        //Initialize Model
        board = new Board();

        //Initialize Movement Model
        moveModel      = gameObject.AddComponent <MoveModel> ();
        capturedPieces = new List <Piece> ();

        //Initialize View
        //drawBoard.InitBoard();
        var startingPositions = drawPiece.InitPieces();

        for (int i = 0; i < startingPositions.t1.Count; ++i)
        {
            Piece blackPiece = CreatePieceAt(startingPositions.t1[i].t1, startingPositions.t1[i].t2, ChessGlobals.Teams.BLACK_TEAM);
            Piece whitePiece = CreatePieceAt(startingPositions.t2[i].t1, startingPositions.t2[i].t2, ChessGlobals.Teams.WHITE_TEAM);

            board.Mark(blackPiece.GetPiecePosition(), blackPiece);
            board.Mark(whitePiece.GetPiecePosition(), whitePiece);

            board.AddActivePiece(whitePiece);
            board.AddActivePiece(blackPiece);
        }
    }
コード例 #2
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);
    }