Example #1
0
 //called when piece is clicked on
 //will highlight valid spots on board
 public List <GameObject> showValidMoves(GameBoardTs board)
 {
     // return array list of possible board cells
     if (isKinged)
     {
         return(movement.getValidKingMoves(position, board));
     }
     else
     {
         return(movement.getValidMoves(position, board));
     }
 }
Example #2
0
 public void checkWinState(bool isBlacksTurn, GameBoardTs board)
 {
     if (board.getWinState(isBlacksTurn, board))
     {
         if (isBlacksTurn)
         {
             // winLoseText.text = "Black Wins";
         }
         else
         {
             //winLoseText.text = "Red Wins";
         }
     }
 }
Example #3
0
        // Start the game
        public void Start()
        {
            // the player hits play game, or start whatever
            // code to initialize the game:
            // also the host is black, opponent is red
            Instance = this;

            //connect client
            //c = FindObjectOfType<Client>();
            //if (c != null) { playerBlack = c.isHost; }

            //set board up
            board = gameObject.GetComponent <GameBoardTs>();
            board.CreateBoard();
            board.placeInitialPieces();
            isBlacksTurn = true;
            changeTurn   = true;
        }
Example #4
0
        // This function is used to check the win state of a particular team
        // it returns false immeditely upon discovering that just one piece has possible moves
        public bool getWinState(bool isBlacksTurn, GameBoardTs board)
        {
            //check pieces on squares on even columns
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (squares[i * 2, j * 2].GetComponent <BoardCellTs>().checkIfOccupied())
                    {
                        if (pieces[i * 2, j * 2].GetComponent <CheckerPieceTs>().getColor() != isBlacksTurn)
                        {
                            if (pieces[i * 2, j * 2].GetComponent <CheckerPieceTs>().showValidMoves(board).Count > 0)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            //check pieces on squares on odd columns
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (squares[(i * 2) + 1, (j * 2) + 1].GetComponent <BoardCellTs>().checkIfOccupied())
                    {
                        if (pieces[(i * 2) + 1, (j * 2) + 1].GetComponent <CheckerPieceTs>().getColor() != isBlacksTurn)
                        {
                            if (pieces[(i * 2) + 1, (j * 2) + 1].GetComponent <CheckerPieceTs>().showValidMoves(board).Count > 0)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            //return true when no pieces had any possible moves
            return(true);
        }
Example #5
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 #6
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
        }