-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameLogic.py
More file actions
43 lines (34 loc) · 1.63 KB
/
GameLogic.py
File metadata and controls
43 lines (34 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
This module defines the `GameLogic` class, which manages the core mechanics of the Reversi game.
The `GameLogic` class is responsible for applying moves to the game board, flipping opponent pieces as needed,
and interacting with the `Board` and `MoveLogic` modules to enforce game rules.
"""
from Board import Board
from MoveLogic import MoveLogic
class GameLogic:
"""
Implements the core game mechanics for Reversi.
Methods:
apply_move(board, row, column, color): Places a piece on the board, flips opponent pieces, and updates the board state.
"""
@staticmethod
def apply_move(board: Board, row: int, column: int, color: str):
"""
Applies a move to the game board by placing a piece and flipping opponent pieces as per the rules.
Args:
board (Board): The game board where the move is applied.
row (int): The row index where the piece is placed.
column (int): The column index where the piece is placed.
color (str): The color of the piece being placed ('W' for white, 'B' for black).
Actions:
- Places the specified piece on the board.
- Calculates which opponent pieces are flipped as a result of the move using `MoveLogic`.
- Flips the relevant pieces on the board.
"""
# Place the piece on the specified cell
board.set_cell(row, column, color)
# Determine which opponent pieces to flip
flipped = MoveLogic.get_flipped_pieces(board, row, column, color)
# Flip the determined pieces
for r, c in flipped:
board.get_cell(r, c).flip()