Skip to content

Commit

Permalink
Fix issue with data
Browse files Browse the repository at this point in the history
  • Loading branch information
s2t2 committed Jan 16, 2022
1 parent dbe4d46 commit 0899516
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

from itertools import cycle
from copy import deepcopy

from app.board import Board
from app.player import select_player
Expand Down Expand Up @@ -46,9 +47,8 @@ def take_turn(self, turn: tuple):
Pass the turn param as a tuple in the form of (player_letter, square_name).
"""
player_letter, square_name = turn
initial_board_state = self.board.notation # important to note this before changing the board

move = Move(board_state=initial_board_state, active_player=player_letter, selected_square=square_name)
initial_board = deepcopy(self.board) # important to note this before changing the board
move = Move(board=initial_board, active_player=player_letter, selected_square=square_name)

# make the move / change the board state:
self.board.set_square(square_name, player_letter)
Expand Down
20 changes: 10 additions & 10 deletions app/jobs/play_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@
records.append({
"game_id": game_counter + 1, # start ids at 1 instead of 0
"move_id": move_counter + 1, # start ids at 1 instead of 0
#"board_state": move.board_state,
"a1": game.board.get_square("A1").notation,
"b1": game.board.get_square("B1").notation,
"c1": game.board.get_square("C1").notation,
"a2": game.board.get_square("A2").notation,
"b2": game.board.get_square("B2").notation,
"c2": game.board.get_square("C2").notation,
"a3": game.board.get_square("A3").notation,
"b3": game.board.get_square("B3").notation,
"c3": game.board.get_square("C3").notation,
"board_state": move.board.notation,
"a1": move.board.get_square("A1").notation,
"b1": move.board.get_square("B1").notation,
"c1": move.board.get_square("C1").notation,
"a2": move.board.get_square("A2").notation,
"b2": move.board.get_square("B2").notation,
"c2": move.board.get_square("C2").notation,
"a3": move.board.get_square("A3").notation,
"b3": move.board.get_square("B3").notation,
"c3": move.board.get_square("C3").notation,
"player": active_player,
"square_name": move.selected_square,
#"square_idx": SQUARE_NAMES.index(move.selected_square), # translate squares to index 0-8 to match board notation (maybe)
Expand Down
10 changes: 5 additions & 5 deletions app/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

class Move:

def __init__(self, board_state, active_player, selected_square):
def __init__(self, board, active_player, selected_square):
"""
Params
board_state (str) the initial board state before the player made the move
board (Board) the initial board state before the player made the move
active_player (str) the letter of the player who made the move ("X" or "O")
selected_square (str) the name of the square the player selected (e.g "A1")
"""
self.board_state = board_state #> "XX-OO----"
self.active_player = active_player #> "X"
self.selected_square = selected_square #> "C1"
self.board = board
self.active_player = active_player
self.selected_square = selected_square

def __repr__(self):
return f"<Move '{self.active_player}' to {self.selected_square} >"

0 comments on commit 0899516

Please sign in to comment.