-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* generalised tic-tac-toe * added example to README (#10) * generalized tic-tac-toe game * added connect 4 game (int#11) * updated README for connect 4 * added main.py for example * added connect 4 game (#11) * updated README for connect 4 * added main.py for example
- Loading branch information
1 parent
58771d1
commit 78ca27d
Showing
4 changed files
with
104 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
*.py[cod] | ||
common/*.pyc | ||
main.py | ||
mnist.py | ||
output/ | ||
output_test/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
from mctspy.games.examples.tictactoe import TicTacToeGameState, TicTacToeMove | ||
|
||
class Connect4GameState(TicTacToeGameState): | ||
|
||
def is_move_legal(self, move): | ||
# check if correct player moves | ||
if move.value != self.next_to_move: | ||
return False | ||
|
||
# check if inside the board on x-axis | ||
x_in_range = (0 <= move.x_coordinate < self.board_size) | ||
if not x_in_range: | ||
return False | ||
|
||
# check if inside the board on y-axis | ||
y_in_range = (0 <= move.y_coordinate < self.board_size) | ||
if not y_in_range: | ||
return False | ||
|
||
# finally check if board field not occupied yet | ||
return self.board[move.x_coordinate, move.y_coordinate] == 0 and (move.y_coordinate == 0 or self.board[move.x_coordinate, move.y_coordinate-1] != 0) | ||
|
||
def get_legal_actions(self): | ||
indices = np.where(np.count_nonzero(self.board,axis=1) != self.board_size)[0] | ||
# print(indices) | ||
return [ | ||
TicTacToeMove(i, np.count_nonzero(self.board[i,:]), self.next_to_move) | ||
for i in indices | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters