Exemple #1
0
		}//end of IsMoveLegal method

		public void EnterMove(int[] move) {
			Move newMove = new Move(move);
			Console.Write($" moves {GameInterface.map_board_location(move[0],move[1])}{GameInterface.map_board_location(move[2], move[3])} ({GameInterface.map_translate_location(move[0], move[1])}{GameInterface.map_translate_location(move[2], move[3])})");
			if(OnBoard(newMove.GetFromRow(), newMove.GetFromCol()) && OnBoard(newMove.GetFromRow(), newMove.GetFromCol())) {
				PIECES piece = board[newMove.GetFromRow(), newMove.GetFromCol()];
				currentHash = currentHash ^ zBoard[(5 * newMove.GetFromRow()) + newMove.GetFromCol(), (int)piece - 1];
				Removal removal = new Removal(newMove.GetToRow(), newMove.GetToCol(), board[newMove.GetToRow(), newMove.GetToCol()]);
				removals.Push(removal);
				if(board[newMove.GetToRow(), newMove.GetToCol()] != PIECES.NONE) {
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)board[newMove.GetToRow(), newMove.GetToCol()] - 1];
				}
				if(piece == PIECES.P1_BISHOP) {
					board[newMove.GetToRow(), newMove.GetToCol()] = PIECES.P1_KNIGHT;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)PIECES.P1_KNIGHT - 1];
				}
				else if(piece == PIECES.P2_BISHOP) {
					board[newMove.GetToRow(), newMove.GetToCol()] = PIECES.P2_KNIGHT;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)PIECES.P2_KNIGHT - 1];
				}
				else if(piece == PIECES.P1_ROOK) {
					board[newMove.GetToRow(), newMove.GetToCol()] = PIECES.P1_BISHOP;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)PIECES.P1_BISHOP - 1];
				}
				else if(piece == PIECES.P2_ROOK) {
					board[newMove.GetToRow(), newMove.GetToCol()] = PIECES.P2_BISHOP;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)PIECES.P2_BISHOP - 1];
				}
				else if(piece == PIECES.P1_KNIGHT) {
					board[newMove.GetToRow(), newMove.GetToCol()] = PIECES.P1_ROOK;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)PIECES.P1_ROOK - 1];
				}
				else if(piece == PIECES.P2_KNIGHT) {
					board[newMove.GetToRow(), newMove.GetToCol()] = PIECES.P2_ROOK;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)PIECES.P2_ROOK - 1];
				}
				else {
					board[newMove.GetToRow(), newMove.GetToCol()] = piece;
					currentHash = currentHash ^ zBoard[(5 * newMove.GetToRow()) + newMove.GetToCol(), (int)piece - 1];
				}
				board[newMove.GetFromRow(), newMove.GetFromCol()] = PIECES.NONE;
			}
		}//end of EnterMove method
Exemple #2
0
		}//end of GetCurrentHash method

		public PIECES[] GetBoardRow(int row) {
			PIECES[] returnValue = new PIECES[6];
			if(row >= 0 && row <= 7) {
				returnValue[0] = board[row, 0];
				returnValue[1] = board[row, 1];
				returnValue[2] = board[row, 2];
				returnValue[3] = board[row, 3];
				returnValue[4] = board[row, 4];
				returnValue[5] = board[row, 5];
			}
			else {
				returnValue[0] = PIECES.NONE;
				returnValue[1] = PIECES.NONE;
				returnValue[2] = PIECES.NONE;
				returnValue[3] = PIECES.NONE;
				returnValue[4] = PIECES.NONE;
				returnValue[5] = PIECES.NONE;
			}
			return returnValue;
		}//end of GetBoardRow method
Exemple #3
0
		}//end of EnterMove method

		public void TryMove(Move move) {
			if(OnBoard(move.GetFromRow(), move.GetFromCol()) && OnBoard(move.GetFromRow(), move.GetFromCol())) {
				PIECES piece = board[move.GetFromRow(), move.GetFromCol()];
				currentHash = currentHash ^ zBoard[(5 * move.GetFromRow()) + move.GetFromCol(), (int)piece - 1];
				Removal removal = new Removal(move.GetToRow(), move.GetToCol(), board[move.GetToRow(), move.GetToCol()]);
				removals.Push(removal);
				if(board[move.GetToRow(), move.GetToCol()] != PIECES.NONE) {
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)board[move.GetToRow(), move.GetToCol()] - 1];
				}
				if(piece == PIECES.P1_BISHOP) {
					board[move.GetToRow(), move.GetToCol()] = PIECES.P1_KNIGHT;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)PIECES.P1_KNIGHT - 1];
				}
				else if(piece == PIECES.P2_BISHOP) {
					board[move.GetToRow(), move.GetToCol()] = PIECES.P2_KNIGHT;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)PIECES.P2_KNIGHT - 1];
				}
				else if(piece == PIECES.P1_ROOK) {
					board[move.GetToRow(), move.GetToCol()] = PIECES.P1_BISHOP;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)PIECES.P1_BISHOP - 1];
				}
				else if(piece == PIECES.P2_ROOK) {
					board[move.GetToRow(), move.GetToCol()] = PIECES.P2_BISHOP;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)PIECES.P2_BISHOP - 1];
				}
				else if(piece == PIECES.P1_KNIGHT) {
					board[move.GetToRow(), move.GetToCol()] = PIECES.P1_ROOK;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)PIECES.P1_ROOK - 1];
				}
				else if(piece == PIECES.P2_KNIGHT) {
					board[move.GetToRow(), move.GetToCol()] = PIECES.P2_ROOK;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)PIECES.P2_ROOK - 1];
				}
				else {
					board[move.GetToRow(), move.GetToCol()] = piece;
					currentHash = currentHash ^ zBoard[(5 * move.GetToRow()) + move.GetToCol(), (int)piece - 1];
				}
				board[move.GetFromRow(), move.GetFromCol()] = PIECES.NONE;
			}
		}//end of TryMove method
        public GameController(Game game, SpriteBatch spriteBatch) : base(game)
        {
            this.game        = game;
            this.spriteBatch = spriteBatch;

            fontS16  = game.Content.Load <SpriteFont>("gameFont_s16");  //loading font
            fontS32b = game.Content.Load <SpriteFont>("gameFont_S32b"); //loading font

            playerTurn = PIECES.PIECEX;                                 //begins with player 1, which is piece X

            gamePieces = new List <GamePiece>();

            //adding the 9 tiles for the tic tac toe grid into the list
            gamePieces.Add(new GamePiece(new Rectangle(74, 71, pieceSizeX, pieceSizeY), 0));
            gamePieces.Add(new GamePiece(new Rectangle(234, 71, pieceSizeX, pieceSizeY), 1));
            gamePieces.Add(new GamePiece(new Rectangle(394, 71, pieceSizeX, pieceSizeY), 2));
            gamePieces.Add(new GamePiece(new Rectangle(74, 236, pieceSizeX, pieceSizeY), 3));
            gamePieces.Add(new GamePiece(new Rectangle(234, 236, pieceSizeX, pieceSizeY), 4));
            gamePieces.Add(new GamePiece(new Rectangle(394, 236, pieceSizeX, pieceSizeY), 5));
            gamePieces.Add(new GamePiece(new Rectangle(74, 397, pieceSizeX, pieceSizeY), 6));
            gamePieces.Add(new GamePiece(new Rectangle(234, 397, pieceSizeX, pieceSizeY), 7));
            gamePieces.Add(new GamePiece(new Rectangle(394, 397, pieceSizeX, pieceSizeY), 8));
        }
        public override void Update(GameTime gameTime)
        {
            MouseState mouse = Mouse.GetState(); //grabbing mousestate

            mousePosition.X = mouse.X;           //x position
            mousePosition.Y = mouse.Y;           //y position

            currPieceRectangle = new Rectangle((int)MousePosition.X - 55, (int)MousePosition.Y - 55, 110, 110);

            if (gameOver == true) //if game has finished
            {
                //resetting the pieces on the board
                foreach (GamePiece piece in GamePieces)   //go through list
                {
                    piece.WhichPiece = PIECES.PIECEEMPTY; //and reset all pieces back to empty, this way the draw part will know
                }
                movesLeft  = 9;
                playerTurn = PIECES.PIECEX; //x's go first, so player 1
            }
            else
            {
                currCollidedPiece = -1;                                      //set piece to one that can't exist
                foreach (GamePiece piece in GamePieces)                      //checking each piece to see if theres currently a intersect happening
                {
                    if (piece.PieceRectangle.Intersects(currPieceRectangle)) //if there is, set current piece to the intersecting one
                    {
                        currCollidedPiece = piece.PiecePosition;
                    }
                }

                if (mouse.LeftButton == ButtonState.Pressed)                           //if player has clicked mouse, this will allow player to drag mouse over grid and randomly draw X or Os
                {
                    if (gamePieces[currCollidedPiece].WhichPiece == PIECES.PIECEEMPTY) //if the selected piece is empty
                    {
                        gamePieces[currCollidedPiece].WhichPiece = playerTurn;         //set the grid piece to current player piece
                        hasPlayerGone = true;                                          //yes player has gone
                        movesLeft--;                                                   //negatively interate once every time a player has performed a move
                    }
                }

                if (CheckForWinner())                //calls check for winner to see if latest move resulted in a win
                {
                    hasPlayerGone = false;           //set to false

                    if (PlayerTurn == PIECES.PIECEX) //which ever player just went and has triggered winning condition, wins
                    {
                        gameMessage = "Player (X) is the winner!";
                        gameOver    = true;
                    }
                    else
                    {
                        gameMessage = "Player (O) is the winner!";
                        gameOver    = true;
                    }
                }
                else if (movesLeft <= 0)
                {
                    gameMessage = "Boooo, no one won!";
                    gameOver    = true;
                    movesLeft   = 9; //resetting to 9 moves left
                }
                else
                {
                    if (playerTurn == PIECES.PIECEX && hasPlayerGone)      //if it is X/player 1
                    {
                        gameMessage   = "It is now Player (O)'s turn!";    //what turn
                        playerTurn    = PIECES.PIECEO;                     //which player, x or o
                        hasPlayerGone = false;                             //reset has player moved to false
                    }
                    else if (playerTurn == PIECES.PIECEO && hasPlayerGone) //if it is O/player 2
                    {
                        gameMessage   = "It is now Player (X)'s turn!";
                        playerTurn    = PIECES.PIECEX;
                        hasPlayerGone = false;
                    }
                }
            }

            base.Update(gameTime);
        }
Exemple #6
0
 public GamePiece(Rectangle pieceRectangle, int piecePosition)
 {
     this.pieceRectangle = pieceRectangle;    //initializes with a rectangle
     this.piecePosition  = piecePosition;     //in the 3x3 grid, which spot does this belong to?
     whichPiece          = PIECES.PIECEEMPTY; //initalizes with empty game piece on board
 }