How to play: The main function requires the following arguments:
- -p1 strategy
- -p2 strategy
Where strategy is one of our strategies:
- human
- first-move
- highest-scoring
- combined
- tree-minimax
- console
- capture
- avoid
- corner
- minimax
- combo
And accepts the following additional arguments:
- -s n or -size n, where n is an integer greater than 2
- -d n or -depth n where n is a positive integer. WARNING: Using tree-minimax with a depth that is above 3 or on a very large board can cause out of memory errors.
- -v1 ours, or -v1 provider, which chooses which view to use for player 1
- -v2 ours, or -v2 provider, which chooses which view to use for player 2
Controls: For our view moves are made by clicking on the respective cell and passing is done by clicking the pass-turn button. For the provider view moves are made by clicking on a cell and then pressing Enter, and passing turn is done by clicking s.
Invariants:
- All three lists contain the same cells
- The horizontal rows 0 indexed from top Reversi is a two-player game played on a regular grid of cells. Each player has a color—black or white—and the game pieces are discs colored black on one side and white on the other. Game play begins with equal numbers of both colors of discs arranged in the middle of the grid. In our game, our grid will be made up of hexagons.
Player Black moves first. On each turn, a player may do one of two things: They may pass, and let the other player move. They may select a legal empty cell and play a disc in that cell.
A play is legal for player A if the disc being played is adjacent 1 (in at least one direction) to a straight line of the opponent player B’s discs, at the far end of which is another player A disc. The result of a legal move is that all player B’s discs in all directions that are sandwiched between two discs of player A get flipped to player A. We say that player A has captured player B’s discs.
If a player has no legal moves, they are required to pass. If both players pass in a row, the game ends.
Modeling game: The board is represented by 3 2d arrays of cells representing the cells of the game ordered along all three axis of a hexagon.
Visualizing game:
You are not required in this assignment to create a GUI view of your game. Instead, you will start with a
simpler textual view.
Textual view:
_ _ _
_ _ _ _
_ _ X O _ _
_ _ O _ X _ _
_ _ X O _ _
_ _ _ _
_ _ _
Player one Score: 3
Player two Score: 3
Player one turn (Black)!
where
X - Player one with Black colored Disc
O - Player two with White colored Disc
Source details:
- BasicReversi model implements the Reversi game. This model uses 2 players Player One and Player Two. It uses Hex coordinates based grid. It has horizontal, down left and down right rows. Each cell extends Location (x,y) coordinates and may have Player's state if it is used by player.
- ReversiTextualController to take Player One moves from user input, play move and display the output.
- ReversiTextualView to display the textual output.
- Classes are implemented for future use:
Player.java, BlackPlayer.java, WhitePlayer.java, HexGrid.java, Point.java - Functionalities need to be updated for future work such as down left or right rows to support those directional moves.
Rule details:
- Reversi game is implemented with below rules to ensure the move is valid:
a. The cell to move in is empty.
b. The cell to move in is adjacent to the one of the opponent player's cells.
c. When moving in that direction there is a friendly player cell before empty cell/end of list. - Horizontal moves are implemented. It also flips opposite player's discs if move is valid as per the rules of the game.
- Game pass turns are implemented. If both players pass their turns in a row then game will be over.
Added:
- isGameOver();
a. The interface did not expose a way to check if the game was over, so we added a method to do that. - getTileAt(hRow, hIndex);
a. The interface did not expose a way to see the state of a specific tile, so we added a method to do that. - getGameBoard();
a. The only way to get the state of the game before was to parse the string from the toString method, so we added a method to get the state of each cell. - ReadonlyReversiModel interface is created to only support views.
- ReversiHexGridController is implemented to support GUI based mouse click game actions and views.
- ReversiFrame interface is created to support GUI based view. BasicReversiView is implemented to support this interface.
- Hexagon is created to build the Hexagon based grid.
- Reversi and ReversiGUI Main classes allows one to play this Reversi game in textual and GUI views.
- Make move mouse clicks, Pass Turn button clicks and Restart button clicks are implemented as part of Hexagonal Grid GUI based game.
- Strategy pattern is implemented to simulate the computer Move for selected player.
PromptUser, FirstAvailableOpening moves are implemented. - Player is implemented to run as per his strategical move.
- If computer player do not have any valid moves left then computer will automatically pass turn.
- Vertical down left and right moves are implemented.
- Display of Winner and Tie messages are implemented.
- Mouse move over motion is implemented to display the associated cell as highlighted.
- Keyboard support is implemented to support make-move and pass-turn commends as part of Reversi GUI.
New constructor:
- We did not have a way to set up scenarios to test the model in specific situations,
so we added a new constructor that takes in a list of locations for white tiles and for black tiles
as well as other information about the state of the game.
- We also added a copy constructor to be able to make copies of a game in progress.
a. This required also adding a copy constructor to the cell class.
Added:
- Keyboard support is implemented to support make-move, pass-turn, restart and quit commends as part of ReversiGUI.
- Reversi main class is created to accept command line strategies from user to simulate the computer player strategy.
If Strategy is unable to return valid move then it defaults to pass turn. For example:
Reversi "Human" "Human"
Reversi "Human" "FirstMove"
Reversi "Human" "HighestScoring"
Reversi "Human" "Combined"
Reversi "Human" "MiniMax"
Reversi "Human" "Console"
where
FirstMove - First Available Opening Strategy
HighestScoring - Highest Scoring Strategy
Combined - Combined Moved Strategy using Pass If Win, Corners and Highest Scoring Move
MiniMax - Game tree search of depth 2 using minimax to choose the best move
Console - Console based Moves Strategy
Human - Human Mouse or Keys based Moves Strategy - Mouse event handling decoupled from controller, view now sends the controller the logical result of the click instead of exact location
- Implemented 2 Controllers and 2 Views as Part3 requirements as part of Reversi main class method and kept Part 2 implementation as part of previous ReversiGUI main class method.
- Your Turn and Refresh View events are implemented to enable Player 2 to simulate the moves as per implemented strategies.
- Manifest file is now using cs3500.reversi.Reversi as main class.
- Keyboard support is implemented to support below keys using Key Listener, Key Bindings and Key Release event
Up, Down, Left and Right Arrow keys will allow user to move selected cell on the game board.
P for Pass-Turn, R for Restart and Q for Quit will allow user to make actions on the game board. - Above Strategies are tested through test class.
- Created mock for the model that records all method calls and their arguments in a transcript including method calls in copies of the model. This allows strategies to be tested by seeing which of the legal moves they check.
Added:
- Integrated Provider view for player2 based upon command line params.
- Reversi main class is updated to accept command line strategies from user to simulate the computer player strategy.
New command line parameters are added to Reversi main class to determine ours Team strategy vs provider Team strategy.
For example:
Reversi -s 4 -p1 Human -p2 Human -v1 Ours -v2 Ours
Reversi -s 4 -p1 Human -p2 First-Move -v1 Ours -v2 Ours
Reversi -s 4 -p1 Human -p2 Highest-Scoring -v1 Ours -v2 Ours
Reversi -s 4 -p1 Human -p2 Combined -v1 Ours -v2 Ours
Reversi -s 4 -p1 Human -p2 Tree-MiniMax -v1 Ours -v2 Ours
Reversi -s 4 -p1 Human -p2 Console -v1 Ours -v2 Ours
Reversi -s 4 -p1 Human -p2 Human -v1 Ours -v2 Provider
Reversi -s 4 -p1 Human -p2 Capture -v1 Ours -v2 Provider
Reversi -s 4 -p1 Human -p2 Avoid -v1 Ours -v2 Provider
Reversi -s 4 -p1 Human -p2 Corner -v1 Ours -v2 Provider
Reversi -s 4 -p1 Human -p2 MiniMax -v1 Ours -v2 Provider
Reversi -s 4 -p1 Human -p2 Combo -v1 Ours -v2 Provider
where
Valid strategy values from Ours:
First-Move - First Available Opening Strategy
Highest-Scoring - Highest Scoring Strategy
Combined - Combined Moved Strategy using Pass If Win, Corners and Highest Scoring Move
Tree-MiniMax - Game tree search of depth 2 using minimax to choose the best move
Console - Console based Moves Strategy
Human - Human Mouse or Keys based Moves Strategy
Valid strategy values from Provider:
Capture - Capture Max Strategy
Avoid = Avoid Next To Corner Strategy
Corner - Go For Corner Strategy
MiniMax - Mini Max to choose the best move
Combo - Combined Move Strategy using MiniMax, Corner, Avoid and Capture
Human - Human Mouse or Keys based Moves Strategy - Implemented adaptors to support integration of our models, controllers, players, and views with provider strategies and view.
- Provider strategies integrated with both provider view and our view.
- Showing scoring hints (i.e. Level 0) is implemented. New Listener is added to support this hints feature. Each player can enable or disable the scoring hints using the Hints button on player view, and they will then receive this event with respect to only their view.
- ExamplarPlayerTests class is added to ensure that all possible hints are validated.
- Square Reversi (i.e. Level 1) is implemented using HexagonalBoard and SquareBoard.
- ReversiText is updated to play the game using HEXAGON or SQUARE as board type with textual view displayed on console and one can play game using console based commands such as make-move row col or pass-turn or quit commands.
For example:
ReversiText 4 HEXAGON
ReversiText 4 SQUARE
where
1st param - SideLength. It must be at-least 3 or above and it must be even number for SQUARE board type.
2nd param - BoardType. Valid values are HEXAGON, SQUARE. - SquareModelTests class is added to ensure that all possible horizontal, vertical and diagonal valid moves are validated. It is also validating the invalid arguments.
- Visualizing Square Reversi (i.e. Level 2) is implemented using SquareMainPanel and SquareReversiView. It is implemented to support both HEXAGON and SQUARE boards views based upon type of board created.
- Controlling Square Reversi (i.e. Level 3) is implemented. It is implemented to support both HEXAGON and SQUARE boards.
- Strategic Square Reversi (i.e. Level 4) is implemented. It is implemented to support both HEXAGON and SQUARE boards.