9 Men’s Morris
(Summer vacation edition)
Part 0: Installation
-
Simple Installation
- Go to Releases
- Find the latest release
- Download and follow instructions
-
Building from source
- Clone the repo
git clone https://github.com/Legedith/9-men-s-morris.git - cd into the cloned repo
cd 9-men-s-morris - Compile using Javac
javac morris.java - Run the compiled game
java morris
- Clone the repo
Part 1: Analysis of the game 🕵️♀️
9 Men’s Morris is a classical 2 person game. The game starts with each player having three pieces each. The game consists of two phases; the placement phase and the movement phase. It’s won when either player manages to get three pieces in a row. In the placement phase, the players take turns placing their pieces on the board. Once they run out of pieces, the placement phase begins. In the placement phase, the players can pick their pieces and place them at any blank location. The one who gets three in a row first wins.
Part 2: Design 🎨
For the Design of classes, we thought it wise to split the implementation into two classes. One depicting the game board containing all necessary variables to control and represent the game state, and the other to manage players and implement the rules and peculiarities of the game using the methods and variables of the game board. The inspiration for this came from the fact that even in real life, you can play multiple games on the same game board by modifying the rules, the pieces and such.
P.s. you can even play a variation of tic-tac-toe on the same game board.
Part 3: Description of classes 🔧🔨
Class gameBoard
Description of class
A class to implement the raw game board. You can create any game and rules using the methods of this game board.
Variables:
board - a 2D array of integers that represents the game board
turn - an integer that represents whose turn it is
winner - an integer that represents the winner of the game
placed - an integer that represents the number of pieces placed on the board
Methods:
Function placePiece
Description of function
Places a piece on the board
Parameters:
x - an integer that represents the x coordinate of the piece to be placed
y - an integer that represents the y coordinate of the piece to be placed
Returns:
1 if the move is successful, 0 if not
Function checkWin
Description of function
Checks if any player has 3 in a row, column, or diagonal
Board will have 1 for player 1, 2 for player 2, and 0 for empty
Parameters: None
Returns: 1 if player 1 wins, 2 if player 2 wins, 0 if no one wins
Function move
Description of function
Moves a piece from one space to another
Parameters:
fromRow - an integer that represents the row of the piece to be moved
fromCol - an integer that represents the column of the piece to be moved
toRow - an integer that represents the row to move the piece to
toCol - an integer that represents the column to move the piece to
Returns:
1 if the move is successful, 0 if not
Function getTurn
Description of function
Returns the current turn
Function setTurn
Description of function
Sets the current turn
Parameters:
turn - an integer that represents the turn to be set
Return: None
Function getPossibleMoves
Description of function
Parameters: None
Returns an array of possible moves
Function getWinner
Description of function
Returns the winner of the game
Function isEmpty
Description of function
Checks if the position on the board is empty
Parameters:
row - an integer that represents the row of the position to be checked
col - an integer that represents the column of the position to be checked
Returns:
true if the position is empty, false if not
Function printBoard
Description of function
Prints the board with stars for empty spaces dashes for lines
Parameters:
None
Returns:
None
Function getPlaced
Description of function
Returns the number of pieces placed on the board
Function decrementPlaced
Description of function
Decrements the number of pieces placed on the board
Parameters:
None
Returns:
None
Class morris
Purpose: Implement three mens morris using the board Game starts with empty board The players have 3 pieces each They take turns placing their piece on the board After the pieces are placed, the players take turn moving pieces. The first player to get 3 in a row wins