AlinaNgr / FinalProjectTicTacToe

0 stars 0 forks source link

02.Task - Check winner and make move #3

Open veleadan opened 1 week ago

veleadan commented 1 week ago

Add functions, to the Board Class, that check the winner of the game and that makes a move for the player and for the AI.

AlinaNgr commented 1 week ago

Description of Changes: I implemented the check_winner and make_move methods, along with unit tests to validate their functionality.

check_winner() Function:

This function checks the current state of the game board to determine if there's a winner. It checks: All rows for three identical non-empty values. All columns for three identical non-empty values. Both diagonals for three identical non-empty values. If a winner is found, it returns the player ("X" or "O"), otherwise it returns None.

make_move() Function:

This function allows a player to make a move if the specified board cell is empty. It takes as arguments the row, column, and player ("X" or "O"), and updates the board accordingly if the move is valid. Returns True if the move is successful, False if the cell is already occupied. Unit Tests:

Added unit tests using Python’s unittest framework to ensure the functions behave as expected: Tests for check_winner(): Verify that the function correctly identifies a winner in rows, columns, and diagonals. Check the case where there is no winner (draw). Tests for make_move(): Validate that a move can be made if the cell is empty. Check that the function returns False if the cell is already occupied. These additions ensure that the game logic for identifying a winner and handling player moves is functioning correctly and is properly tested.