Question
Code using java
Three Men's Morris
Three Men's Morris is played on a three by three board (counting
lines) and is a game of position. The figure below indicates the
type of board:
The game is thought to be a direct ancestor of tic-tac-toe. It is
also related to Six Men's Morris and Nine Men's Morris.
The game is played with two sets of three pieces (one set for each
player), with each set having its own colour. Each player takes
it in turn to place pieces on intersection points, the first
person to place three along a line wins the game. Once all six
pieces are placed (assuming there is no winner by then), play
proceeds with each player moving one of their own pieces per turn.
A piece may be moved one line segment per turn.
Implement the game of Three Men's Morris
using Swing.
Thank you.
Tic Tac Toe example using this example to make Three Men's Morris
Explanation / Answer
public class BitBoard { public static final int White = 0; public static final int Black = 1; public long[] board = { 0, 0 }; public int Player = 0; public int[] left = { 9, 9 }; public int Opponent() { return Player == White ? Black : White; } public void makemove(int from, int to, int capture) { if (from == 0) { assert left[Player] > 0 : "makemove: no left"; left[Player]--; } if (from != 0) { assert (board[Player] & from) != 0 : "makemove: source empty"; board[Player] &= ~from; } assert (board[Player] & to) == 0 : "makemove: target must be empty"; board[Player] |= to; if (capture != 0) { assert (board[Opponent()] & capture) != 0 : "makemove: capture empty"; board[Opponent()] &= ~capture; } } public void unmakemove(int from, int to, int capture) { if (capture != 0) { assert (board[Opponent()] & capture) == 0 : "unmakemove: capture empty"; board[Opponent()] |= capture; } assert (board[Player] & to) != 0 : "unmakemove: target empty"; board[Player] &= ~to; if (from != 0) { assert (board[Opponent()] & capture) != 0 : "unmakemove: source must be empty empty"; board[Player] |= from; } if (from == 0) { assert left[Player] < 9 : "unmakemove: too many left"; left[Player]++; } } public void generatemoves() { // determine phase // } }