Example #1
0
        //Function that handles all actual game moves
        public void gameMove(int squareX, int squareY, int pieceX, int pieceY, string toChange, string toForce)
        {
            if (!forceCapture && toForce == "yes")
            {
                forceCapture = true;
            }

            if (forceCapture && toForce == "no")
            {
                forceCapture = false;
            }

            //get board cell we're touching
            GameObject square = board.getBoardCell(squareX, squareY);

            //If the piece exists (on the other client), move it
            if (board.getPieceOnBoard(pieceX, pieceY) != null)
            {
                //Move the piece
                GameObject piece = board.getPieceOnBoard(pieceX, pieceY);
                piece.GetComponent <PieceMovementTs>().move(piece, square.GetComponent <BoardCellTs>());
                board.setPieceOnBoard(piece, square.GetComponent <BoardCellTs>().getPosition()[0], square.GetComponent <BoardCellTs>().getPosition()[1]);
                //Remove piece from previous position
                board.clearPieceOnBoard(pieceX, pieceY);
                //Check if piece was a jump
                eliminatePiece(squareX, squareY, pieceX, pieceY);
            }

            //check if someone has won after every move
            checkWinState(isBlacksTurn, board);

            if (changeTurn)
            {
                scanForCapture();
            }
        }
Example #2
0
        //This method returns a List of valid moves for a kinged piece
        public List <GameObject> getValidKingMoves(int[] pos, GameBoardTs board)
        {
            List <GameObject> Lbc     = new List <GameObject>();
            List <GameObject> jumpLbc = new List <GameObject>();
            int x = pos[0];
            int y = pos[1];
            int check;

            // A king can move in all directions

            // upper left
            check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x - 1, y + 1), board.getBoardCell(x - 2, y + 2));
            if (check == 1)
            {
                Lbc.Add(board.getBoardCell(x - 1, y + 1));
            }
            else if (check == 2)
            {
                jumpLbc.Add(board.getBoardCell(x - 2, y + 2));
            }

            // upper right
            check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x + 1, y + 1), board.getBoardCell(x + 2, y + 2));
            if (check == 1)
            {
                Lbc.Add(board.getBoardCell(x + 1, y + 1));
            }
            else if (check == 2)
            {
                jumpLbc.Add(board.getBoardCell(x + 2, y + 2));
            }

            // bottom left
            check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x - 1, y - 1), board.getBoardCell(x - 2, y - 2));
            if (check == 1)
            {
                Lbc.Add(board.getBoardCell(x - 1, y - 1));
            }
            else if (check == 2)
            {
                jumpLbc.Add(board.getBoardCell(x - 2, y - 2));
            }

            // bottom right
            check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x + 1, y - 1), board.getBoardCell(x + 2, y - 2));
            if (check == 1)
            {
                Lbc.Add(board.getBoardCell(x + 1, y - 1));
            }
            else if (check == 2)
            {
                jumpLbc.Add(board.getBoardCell(x + 2, y - 2));
            }

            if (jumpLbc.Count == 0)
            {
                return(Lbc);
            }
            else
            {
                return(jumpLbc);
            }                        //A king must also take a jump if available
        }
Example #3
0
        //This method returns a List of valid moves for a regular piece
        public List <GameObject> getValidMoves(int[] pos, GameBoardTs board)
        {
            List <GameObject> Lbc     = new List <GameObject>(); //regular moves
            List <GameObject> jumpLbc = new List <GameObject>(); //possible jump moves
            int x = pos[0];
            int y = pos[1];
            int check;

            // First, if its black
            // true if black, false if not
            if (board.getBoardCell(x, y).GetComponent <BoardCellTs>().getPiece().getColor())
            {
                // upper left
                check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x - 1, y + 1), board.getBoardCell(x - 2, y + 2));
                if (check == 1)
                {
                    Lbc.Add(board.getBoardCell(x - 1, y + 1));
                }
                else if (check == 2)
                {
                    jumpLbc.Add(board.getBoardCell(x - 2, y + 2));
                }

                // upper right
                check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x + 1, y + 1), board.getBoardCell(x + 2, y + 2));
                if (check == 1)
                {
                    Lbc.Add(board.getBoardCell(x + 1, y + 1));
                }
                else if (check == 2)
                {
                    jumpLbc.Add(board.getBoardCell(x + 2, y + 2));
                }
            }
            else //else, it must be red
            {
                // bottom left
                check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x - 1, y - 1), board.getBoardCell(x - 2, y - 2));
                if (check == 1)
                {
                    Lbc.Add(board.getBoardCell(x - 1, y - 1));
                }
                else if (check == 2)
                {
                    jumpLbc.Add(board.getBoardCell(x - 2, y - 2));
                }

                // bottom right
                check = checkSpace(board.getBoardCell(x, y), board.getBoardCell(x + 1, y - 1), board.getBoardCell(x + 2, y - 2));
                if (check == 1)
                {
                    Lbc.Add(board.getBoardCell(x + 1, y - 1));
                }
                else if (check == 2)
                {
                    jumpLbc.Add(board.getBoardCell(x + 2, y - 2));
                }
            }

            if (jumpLbc.Count == 0)
            {
                return(Lbc);
            }
            else
            {
                return(jumpLbc);
            }                        //if there are jumps, a jump must be made
        }