Last active
September 3, 2018 22:21
-
-
Save ltbringer/4b00888ed522b6e2b2850ff99f517140 to your computer and use it in GitHub Desktop.
reinforcement_tic_tac_toe_snippet_1
This file contains hidden or 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
def __init__(self, n=3, player_sym='x'): | |
""" | |
Constructor of the Board class, creates board objects. | |
- n(default=3) int: The number of rows and columns in the tic-tac-toe board. | |
- player_sym(default='x') str: The symbol chosen by a human player. | |
""" | |
self.board = None | |
self.reset_board(n) | |
# Initalize the board | |
self.sym_o = { | |
'mark': 'O', | |
'value': 1 | |
} | |
# Setup the 'O' symbol | |
self.sym_x = { | |
'mark': 'X', | |
'value': 2 | |
} | |
# Setup the 'X' symbol | |
self.sym_empty = { | |
'mark': ' ', | |
'value': 0 | |
} | |
# Setup the default ' ' Symbol | |
self.player_sym, self.bot_sym = (self.sym_x, self.sym_o) \ | |
if player_sym.lower() == 'x' \ | |
else (self.sym_o, self.sym_x) | |
# Ensure different symbols are assigned to the bot and the player. | |
self.winner = None | |
# Initialize the winner as None | |
def reset_board(self, n=3): | |
""" | |
params: | |
- n(default=3): int: The number of rows and columns in the tic-tac-toe board. | |
Clear the board when the game is to be restarted or a new game has to be started. | |
""" | |
self.board = np.zeros((n, n)) | |
self.winner = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment