Пример #1
0
 def test_check_diagonal_symbol_mismatch(self):
     board = Board()
     board.insert('O', 0, 0)
     board.insert('X', 4, 4)
     checker = LogicChecker(board)
     
     assert checker._check_diagonal('O', 2, 2) == False
Пример #2
0
 def test_check_diagonal_other_symbol(self):
     board = Board()
     board.insert('O', 0, 0)
     board.insert('O', 4, 4)
     checker = LogicChecker(board)
     
     assert checker._check_diagonal('O', 2, 2) == True
Пример #3
0
 def test_check_diagonal_last_row_false(self):
     board = Board()
     board.insert('X', 0, 2)
     board.insert('X', 2, 2)
     checker = LogicChecker(board)
     
     assert checker._check_diagonal('X', 4, 4) == False
Пример #4
0
    def test_check_vertical_second_column(self):
        board = Board()
        board.insert('X', 2, 0)
        board.insert('X', 2, 2)
        checker = LogicChecker(board)

        assert checker._check_vertical('X', 2, 4) == True
Пример #5
0
    def test_check_vertical_first_column_false(self):
        board = Board()
        board.insert('X', 0, 0)
        board.insert('X', 0, 2)
        checker = LogicChecker(board)

        assert checker._check_vertical('X', 2, 4) == False
Пример #6
0
 def test_check_diagonal_first_row(self):
     board = Board()
     board.insert('X', 4, 4)
     board.insert('X', 2, 2)
     checker = LogicChecker(board)
     
     assert checker._check_diagonal('X', 0, 0) == True
Пример #7
0
 def test_two_remaining(self):
     board = Board()
     checker = LogicChecker(board)
     checker.turn = 8
     board.game_board = [['X', '|', 'O', '|', 'X'],
                         ['--', '+', '--', '+', '--'],
                         ['X', '|', 'O', '|', ' '],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', 'X', '|', ' ']]
     assert checker.would_this_be_a_draw('O', [(4,2), (4,4)]) == True
Пример #8
0
 def test_one_remaining_2(self):
     board = Board()
     checker = LogicChecker(board)
     checker.turn = 9
     board.game_board = [['X', '|', 'X', '|', 'O'],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', ' ', '|', 'X'],
                         ['--', '+', '--', '+', '--'],
                         ['X', '|', 'O', '|', 'O']]
     assert checker.would_this_be_a_draw('X', [(2,2)]) == True
Пример #9
0
 def test_diagonal_victory_in_1(self):
     board = Board()
     checker = LogicChecker(board)
     checker.turn = 9
     board.game_board = [[' ', '|', 'X', '|', 'O'],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', 'X', '|', 'X'],
                         ['--', '+', '--', '+', '--'],
                         ['O', '|', 'O', '|', 'X']]
     assert checker.would_this_be_a_draw('X', [(0,0)]) == False
Пример #10
0
 def test_empty_board(self):
     board = Board()
     checker = LogicChecker(board)
     board.game_board = [[' ', '|', ' ', '|', ' '],
                         ['--', '+', '--', '+', '--'],
                         [' ', '|', ' ', '|', ' '],
                         ['--', '+', '--', '+', '--'],
                         [' ', '|', ' ', '|', ' ']]
     assert checker.would_this_be_a_draw('X', [(0,0),(2,0),(4,0),
                                               (0,2),(2,2),(4,2),
                                               (0,4),(2,4),(4,4)]) == False
Пример #11
0
    def test_mistake_possible_2(self):
        board = Board()
        checker = LogicChecker(board)
        checker.turn = 8

        board.game_board = [['X', '|', ' ', '|', 'X'],
                            ['--', '+', '--', '+', '--'],
                            ['X', '|', 'X', '|', 'O'],
                            ['--', '+', '--', '+', '--'],
                            ['O', '|', 'O', '|', ' ']]

        checker.board.draw()

        assert checker.would_this_be_a_draw('O', [(2,0), (4,4)]) == False
Пример #12
0
    def test_check_diagonal_topright_to_bottom_left(self):
        board = Board()
        board.insert('X', 4, 0)
        board.insert('X', 2, 2)
        checker = LogicChecker(board)

        board.draw()
        
        assert checker._check_diagonal('X', 0, 4) == True
Пример #13
0
    def test_check_diagonal_middle_row_false(self):
        board = Board()
        board.insert('X', 0, 0)
        board.insert('X', 4, 0)
        checker = LogicChecker(board)

        board.draw()
        
        assert checker._check_diagonal('X', 2, 2) == False
Пример #14
0
 def test_is_this_move_a_victory(self):
     board = Board()
     checker = LogicChecker(board)
     assert checker.is_this_move_a_victory('X', 2, 3) == False
Пример #15
0
    def would_this_be_a_draw(self, current_player, empty_tiles_coordinates):
        """Checks whether the current gameboard setting results in a draw.
                Accepts a string next_player 'X' or 'Y', and a list of tuples. 
                    The string represents the player with the current move.
                    The tuples are the coordinates for all empty tiles.
        """

        next_player = self.player_opposites[
            current_player]  #The code here makes predictions about next round

        if self.turn == 7:  #There are two open tiles left

            current_positions_as_dict = self.board.get_tiles_as_dict()
            """There are two scenarios. One takes place if player 'O' chooses one tile; the other if he chooses the other tile."""

            scenario1_future_positions = current_positions_as_dict
            scenario2_future_positions = current_positions_as_dict

            #Scenario 1
            # This scenario assumes the relevant player chooses the tile represented by empty_tile_coordinates[0]
            # This means the opposing player must choose empty_tile_coordinates[1]
            # So we need to figure out whether this combination would result in a draw

            scenario1_future_positions[next_player].append(
                empty_tiles_coordinates[0])

            scenario1_board = Board(setup=scenario1_future_positions)
            scenario1_logic = LogicChecker(scenario1_board)

            scenario1_boolean = (not self.is_this_move_a_victory(
                current_player, *empty_tiles_coordinates[0]) and
                                 not scenario1_logic.is_this_move_a_victory(
                                     self.player_opposites[next_player], *
                                     empty_tiles_coordinates[1]))

            #Scenario 2
            # Here the scenario is reversed

            scenario2_future_positions[next_player].append(
                empty_tiles_coordinates[1])

            scenario2_board = Board(setup=scenario2_future_positions)
            scenario2_logic = LogicChecker(scenario2_board)

            scenario2_boolean = (not self.is_this_move_a_victory(
                current_player, *empty_tiles_coordinates[1]) and
                                 not scenario2_logic.is_this_move_a_victory(
                                     self.player_opposites[next_player], *
                                     empty_tiles_coordinates[0]))

            return (scenario1_boolean and scenario2_boolean)

        elif self.turn >= 8:

            will_there_be_a_victory = self.is_this_move_a_victory(
                next_player, *empty_tiles_coordinates[0])

            return (not will_there_be_a_victory)

        else:
            return False  #We cannot guarantee that there will be a draw
Пример #16
0
 def test_check_horizontal_second_row_false(self):
     board = Board()
     board.insert('X', 0, 2)
     board.insert('X', 2, 2)
     checker = LogicChecker(board)
     assert checker._check_horizontal('X', 2, 4) == False
Пример #17
0
 def test_check_horizontal_first_row(self):
     board = Board()
     board.insert('X', 0, 0)
     board.insert('X', 2, 0)
     checker = LogicChecker(board)
     assert checker._check_horizontal('X', 4, 0) == True
Пример #18
0
 def test_is_this_move_a_victory_true(self):
     board = Board()
     board.insert('X', 0, 0)
     board.insert('X', 2, 2)
     checker = LogicChecker(board)
     assert checker.is_this_move_a_victory('X', 4, 4) == True
Пример #19
0
def board():
    board = Board()
    return board
Пример #20
0
from src.classes.App import App
from src.classes.Board import Board

app = App(title="ChessPy")

board = Board()

app.run()
Пример #21
0
import math

from src.classes.Board import Board
from src.classes.LogicChecker import LogicChecker
from src.classes.InputHandler import InputHandler

board = Board()  #This is the game board itself
logic = LogicChecker(board)

help_board = Board(
)  #This is a board that helps the user pick where to place their X or O.

help_board.insert('1', 0, 0)
help_board.insert('2', 2, 0)
help_board.insert('3', 4, 0)

help_board.insert('4', 0, 2)
help_board.insert('5', 2, 2)
help_board.insert('6', 4, 2)

help_board.insert('7', 0, 4)
help_board.insert('8', 2, 4)
help_board.insert('9', 4, 4)

in_handler = InputHandler(help_board, board)
"""Main Loop"""

current_player = 'X'
while 1:
    print("------------------------------------------------")
    print("\t\tRound ", math.ceil(logic.turn / 2), ":\n\n\tPlayer ",