Write a class named FBoard for playing a game, where player x istrying to get her piece to row 7 and player o is trying to make itso player x doesn’t have any legal moves. It should have thefollowing private data members:
*PYTHON ONLY – PLEASE USE COMMENTS*
IMPORT RANDOM AND CLASS VARIABLES ARE NOT ALLOWED
- An 8×8 list of lists for tracking what’s on each square of theboard.
- A data member for tracking the game state, that holds one ofthe following string values: “X_WON”, “O_WON”, or”UNFINISHED”.
- Data members to keep track of where the x piece is.
The data members should all be private.
- An init method (constructor) that initializes the list of liststo represent an empty 8×8 board (you can use whatever character youwant to represent empty). It should then put four o pieces on row7, in columns 0, 2, 4, and 6. It should put an x piece on row 0,column 3. It should also initialize the other data members.
- A method called get_game_state, that returns the current valueof game_state.
- A method called move_x that takes as parameters the row andcolumn of the square to move to. If the desired move is notallowed, or if the game has already been won, it should just returnfalse. Otherwise, it should make the move and return true. A piecebelonging to x can move 1 square diagonally in any direction. Apiece is not allowed to move off the board or to an occupiedsquare. If x’s move gets her piece to row 7, game_state should beset to “X_WON”.
- A method called move_o that takes as parameters the row andcolumn to move from, and the row and column to move to. If thefirst pair of coordinates doesn’t hold o’s piece, or if the desiredmove is not allowed, or if the game has already been won, it shouldjust return false. Otherwise, it should make the move and returntrue. A piece belonging to o can move 1 square diagonally,but the row cannot increase, so any o piece has atmost two available moves. For example, if player o has a piece at(5, 2), it could move to (4, 1) or (4, 3), but not (6, 1) or (6,3). It is not allowed to move off the board or to an occupiedsquare. If o’s move leaves no legal move for x, game_state shouldbe set to “O_WON”.
You do not need to track whose turn it is. Either move methodcan be called multiple times in a row.
It doesn’t matter which index of the list of lists you considerthe row and which you consider the column as long as you’reconsistent.
Feel free to add helper functions if you want. You may also findit useful to add a print function to help with debugging.
Here’s a very simple example of how the class could be used:
fb = FBoard(); fb.move_x(1,4); fb.move_x(2,5); fb.move_o(7,0,6,1); print(fb.get_game_state());
The file must be named: FBoard.py
*Use PYTHON only! No C++ or Java. Also, IMPORT RANDOMand CLASS VARIABLES are not allowed!
Answer to Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying…