Esempio n. 1
0
        public Game(Player _whitePlayer, Player _blackPlayer)
        {
            WhitePlayer = _whitePlayer;
            BlackPlayer = _blackPlayer;

            Table       = new Piece[RowSize * ColumnSize];
            TableStatus = new int[RowSize * ColumnSize];
            //TableStatus = Enumerable.Repeat(1, RowSize * ColumnSize).ToArray(); // LINQ approach;
            LastMovement  = null;
            LastMovedPawn = null;
            LastCheck     = new List <int>();

            // now adding pieces...
            AddPiece(new PawnPiece(6, 0, PieceColor.Black, this));
            AddPiece(new PawnPiece(6, 1, PieceColor.Black, this));
            AddPiece(new PawnPiece(6, 2, PieceColor.Black, this));
            AddPiece(new PawnPiece(6, 3, PieceColor.Black, this));
            //AddPiece(new PawnPiece(6, 4, PieceColor.Black, this));
            AddPiece(new PawnPiece(6, 5, PieceColor.Black, this));
            AddPiece(new PawnPiece(6, 6, PieceColor.Black, this));
            AddPiece(new PawnPiece(6, 7, PieceColor.Black, this));
            AddPiece(new KnightPiece(7, 1, PieceColor.Black, this));
            AddPiece(new KnightPiece(7, 6, PieceColor.Black, this));
            AddPiece(new BishopPiece(7, 2, PieceColor.Black, this));
            AddPiece(new BishopPiece(7, 5, PieceColor.Black, this));
            AddPiece(new RookPiece(7, 0, PieceColor.Black, this));
            AddPiece(new RookPiece(7, 7, PieceColor.Black, this));
            AddPiece(new QueenPiece(7, 3, PieceColor.Black, this));
            AddPiece(new KingPiece(7, 4, PieceColor.Black, this));

            AddPiece(new PawnPiece(1, 0, PieceColor.White, this));
            AddPiece(new PawnPiece(1, 1, PieceColor.White, this));
            AddPiece(new PawnPiece(1, 2, PieceColor.White, this));
            AddPiece(new PawnPiece(1, 3, PieceColor.White, this));
            //AddPiece(new PawnPiece(1, 4, PieceColor.White, this));
            AddPiece(new PawnPiece(1, 5, PieceColor.White, this));
            AddPiece(new PawnPiece(1, 6, PieceColor.White, this));
            AddPiece(new PawnPiece(1, 7, PieceColor.White, this));
            AddPiece(new KnightPiece(0, 1, PieceColor.White, this));
            AddPiece(new KnightPiece(0, 6, PieceColor.White, this));
            AddPiece(new BishopPiece(0, 2, PieceColor.White, this));
            AddPiece(new BishopPiece(0, 5, PieceColor.White, this));
            AddPiece(new RookPiece(0, 0, PieceColor.White, this));
            AddPiece(new RookPiece(0, 7, PieceColor.White, this));
            AddPiece(new QueenPiece(0, 3, PieceColor.White, this));
            AddPiece(new KingPiece(0, 4, PieceColor.White, this));

            /*
             * AddPiece(new KingPiece(4, 4, PieceColor.White, this));
             * AddPiece(new RookPiece(0, 3, PieceColor.Black, this));
             * AddPiece(new RookPiece(0, 5, PieceColor.Black, this));
             * AddPiece(new RookPiece(3, 1, PieceColor.Black, this));
             * AddPiece(new RookPiece(2, 2, PieceColor.Black, this));
             * AddPiece(new RookPiece(0, 2, PieceColor.Black, this));
             */
            //TableStatus[1] = (int)CellStatus.Movable;

            ActivePlayer = WhitePlayer;
        }
Esempio n. 2
0
        /// <summary>
        /// Move the SelectedPiece to the target cell.
        /// </summary>
        private bool MovePieceTo(int _row, int _col)
        {
            if (LastMovedPawn != null)
            {
                LastMovedPawn.EnPassantEligible = false;
            }
            if (SelectedPiece.Type == PieceType.Pawn)
            {
                LastMovedPawn = SelectedPiece as PawnPiece;
            }
            else
            {
                LastMovedPawn = null;
            }
            // the SelectedPiece is being moved so there is no need to get the piece;
            // the move is always a valid move so there is no need to validate it;
            LastMovement = Tuple.Create(GetIndex(SelectedPiece.Row, SelectedPiece.Column), GetIndex(_row, _col));
            //TableStatus[GetIndex(SelectedPiece.Row, SelectedPiece.Column)] |= (int)CellStatus.LastMove;
            //TableStatus[GetIndex(_row, _col)] |= (int)CellStatus.LastMove;

            Array.Copy(Table, GetIndex(SelectedPiece.Row, SelectedPiece.Column), Table, GetIndex(_row, _col), 1);
            Table[GetIndex(SelectedPiece.Row, SelectedPiece.Column)] = null;
            int pcsRow = _row;

            if (IsFlagSetAtCell(_row, _col, CellStatus.EnPassant))
            {
                if (SelectedPiece.Color == PieceColor.Black)
                {
                    Table[GetIndex(pcsRow + 1, _col)] = null;
                }
                else
                {
                    Table[GetIndex(pcsRow - 1, _col)] = null;
                }
            }
            SelectedPiece.Move(_row, _col);

            UpdateCheckStatus();


            Switch();
            return(true);
        }
Esempio n. 3
0
        // Use this for initialization
        void Start()
        {
            firstClickX = -1;
            firstClickZ = -1;
            playerTurn  = true;           //TODO for other person place switch; //TODO: also switch spaces of queens for other person

            gameSpaces = new GameObject[][] {
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE],
                new GameObject[GAMESIZE]
            };
            gamePieces = new Piece[][] {
                new Piece[GAMESIZE],
                new Piece[GAMESIZE],
                new Piece[GAMESIZE],
                new Piece[GAMESIZE],
                new Piece[GAMESIZE],
                new Piece[GAMESIZE],
                new Piece[GAMESIZE],
                new Piece[GAMESIZE]
            };

            bool odd = true;

            for (int z = 0; z < GAMESIZE; z++)
            {
                for (int x = 0; x < GAMESIZE; x++)
                {
                    if (z < 2)
                    {
                        //TODO: Change color depending on team.
                        GameObject tempObject;
                        string     tempString = "Piece" + x + "," + z;
                        Piece      tempPiece;
                        if (z == 1)
                        {
                            tempObject = Instantiate(pawn, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new PawnPiece(tempString, tempObject, true);
                        }
                        else if (x == 0 || x == GAMESIZE - 1)
                        {
                            tempObject = Instantiate(rook, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new RookPiece(tempString, tempObject, true);
                        }
                        else if (x == 1 || x == GAMESIZE - 2)
                        {
                            tempObject = Instantiate(knight, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new KnightPiece(tempString, tempObject, true);
                        }
                        else if (x == 2 || x == GAMESIZE - 3)
                        {
                            tempObject = Instantiate(bishop, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new BishopPiece(tempString, tempObject, true);
                        }
                        else if (x == 3)
                        {
                            tempObject = Instantiate(queen, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new QueenPiece(tempString, tempObject, true);
                        }
                        else if (x == 4)
                        {
                            tempObject = Instantiate(king, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new KingPiece(tempString, tempObject, true);
                        }
                        else
                        {
                            tempObject = Instantiate(pawn, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new PawnPiece(tempString, tempObject, true);
                        }
                        Renderer rend = tempPiece.getGameObject().GetComponent <Renderer>();
                        rend.material.color = teamColor;
                        gamePieces[x][z]    = tempPiece;
                    }
                    else if (z >= GAMESIZE - 2)
                    {
                        GameObject tempObject;
                        string     tempString = "Piece" + x + "," + z;
                        Piece      tempPiece;
                        if (z == GAMESIZE - 2)
                        {
                            tempObject = Instantiate(pawn, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new PawnPiece(tempString, tempObject, false);
                        }
                        else if (x == 0 || x == GAMESIZE - 1)
                        {
                            tempObject = Instantiate(rook, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new RookPiece(tempString, tempObject, false);
                        }
                        else if (x == 1 || x == GAMESIZE - 2)
                        {
                            tempObject = Instantiate(knight, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new KnightPiece(tempString, tempObject, false);
                        }
                        else if (x == 2 || x == GAMESIZE - 3)
                        {
                            tempObject = Instantiate(bishop, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new BishopPiece(tempString, tempObject, false);
                        }
                        else if (x == 3)
                        {
                            tempObject = Instantiate(queen, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new QueenPiece(tempString, tempObject, false);
                        }
                        else if (x == 4)
                        {
                            tempObject = Instantiate(king, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new KingPiece(tempString, tempObject, false);
                        }
                        else
                        {
                            tempObject = Instantiate(pawn, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                            tempPiece  = new PawnPiece(tempString, tempObject, false);
                        }
                        gamePieces[x][z] = tempPiece;
                    }
                    if (odd)
                    {
                        gameSpaces[x][z] = Instantiate(spaces, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                        gameSpaces[x][z].GetComponent <Renderer>().material.color = teamColor;
                    }
                    else
                    {
                        gameSpaces[x][z] = Instantiate(spaces, new Vector3(x, 0, z), Quaternion.identity) as GameObject;
                        gameSpaces[x][z].GetComponent <Renderer>().material.color = Color.white;
                    }
                    gameSpaces[x][z].transform.name = "Space" + x + "," + z;
                    odd = !odd;
                }
                odd = !odd;
            }
            updateFogOfWarBoard();
        }