Ejemplo n.º 1
0
# E-mail: [email protected]
# Version: 0.0.0 

# IMPORT SECTION
from model.game.board import Board
from model.strategies.position import Number
from model.strategies.blocking2_vs_1 import Blocking2vsBlocking1
from copy import deepcopy

b = [[1, 0, 1, 2, 1, 1, 0],
     [2, 0, 0, 2, 1, 2, 0],
     [1, 0, 0, 1, 2, 2, 0],
     [2, 0, 0, 0, 1, 0, 0],
     [2, 0, 0, 0, 1, 0, 0],
     [1, 0, 0, 0, 2, 0, 0]]
board = Board()
board.board = b
array_number = []

for i in range(0, 7):
    var_number = Number(i)
    array_number.append(var_number)

def test_get_blockers_1():
    """ Check that get_blockers function is working correctly
    """
    strategy = Blocking2vsBlocking1(1, 1, 2)  # Probability 1 (blocking_1) 
    array = strategy.get_blockers(board,1)
    array_result = [1, 2, 3, 5, 6]
    assert(array == array_result)
Ejemplo n.º 2
0
def test_win_hzt_false():
    """Given a cell, check if there is not win from it in horizontal line
    """

    array = [[1, 2, 1, 1, 2, 2, 2], [1, 2, 1, 1, 1, 1,
                                     2], [0, 2, 2, 1, 2, 2, 2],
             [0, 1, 0, 1, 2, 0, 2], [0, 0, 0, 2, 0, 0, 0],
             [0, 0, 0, 0, 0, 0, 0]]
    board = Board()
    board.board = array
    test_pos_1 = [[2, 0], [2, 1], [2, 2], [1, 1], [1, 2], [1, 3]]
    test_pos_2 = [[2, 5], [2, 4], [2, 3], [1, 6], [1, 3], [1, 4]]
    test_pos_3 = [[-1, 0], [10, 3], [5, -4], [9, 0]]
    size_line = 3
    sym_p1 = 1
    sym_p2 = 2
    sym_p3 = 3

    # compare cases left to rigth
    assert (board.win_hzt(test_pos_1[0][0], test_pos_1[0][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_1[1][0], test_pos_1[1][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_1[2][0], test_pos_1[2][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_1[3][0], test_pos_1[3][1], True, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_1[4][0], test_pos_1[4][1], True, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_1[5][0], test_pos_1[5][1], True, sym_p2) <
            size_line)
    # compare cases rigth to left
    assert (board.win_hzt(test_pos_2[0][0], test_pos_2[0][1], False, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_2[1][0], test_pos_2[1][1], False, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_2[2][0], test_pos_2[2][1], False, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_2[3][0], test_pos_2[3][1], False, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_2[4][0], test_pos_2[4][1], False, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_2[5][0], test_pos_2[5][1], False, sym_p2) <
            size_line)
    # compare with symbol not valid
    assert (board.win_hzt(test_pos_1[4][0], test_pos_1[4][1], True, sym_p3) <
            size_line)
    assert (board.win_hzt(test_pos_1[5][0], test_pos_1[5][1], True, sym_p3) <
            size_line)
    assert (board.win_hzt(test_pos_2[4][0], test_pos_2[4][1], False, sym_p3) <
            size_line)
    assert (board.win_hzt(test_pos_2[5][0], test_pos_2[5][1], False, sym_p3) <
            size_line)
    # compare with cell (row, col) not valid
    assert (board.win_hzt(test_pos_3[0][0], test_pos_1[0][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_3[1][0], test_pos_1[1][1], True, sym_p1) <
            size_line)
    assert (board.win_hzt(test_pos_3[2][0], test_pos_2[2][1], False, sym_p2) <
            size_line)
    assert (board.win_hzt(test_pos_3[3][0], test_pos_2[3][1], False, sym_p2) <
            size_line)
Ejemplo n.º 3
0
def test_diag_slash_false():
    """Given a cell, check if there is not win from it in diagonal_slash line
    """

    array = [[1, 2, 1, 1, 2, 2, 2], [1, 2, 1, 2, 2, 1,
                                     2], [1, 1, 2, 1, 1, 2, 2],
             [1, 2, 2, 1, 2, 2, 2], [2, 2, 1, 1, 2, 0, 0],
             [0, 1, 0, 2, 2, 0, 0]]
    board = Board()
    board.board = array
    test_pos_1 = [[3, 0], [4, 0], [3, 1], [5, 1], [4, 2], [5, 3]]
    test_pos_2 = [[0, 3], [0, 4], [1, 3], [1, 5], [2, 4], [2, 6]]
    test_pos_3 = [[-1, 5], [7, 8], [8, 9], [-6, -5]]
    size_line = 3
    sym_p1 = 1
    sym_p2 = 2
    sym_p3 = 3

    # compare cases left to rigth
    test_pos_1 = [[0, 0], [1, 1], [1, 0], [2, 1], [1, 3], [0, 3]]
    test_pos_2 = [[5, 4], [4, 3], [4, 4], [3, 3], [4, 6], [3, 6]]
    test_pos_3 = [[-1, 5], [7, 8], [8, 9], [-6, -5]]
    size_line = 3
    sym_p1 = 1
    sym_p2 = 2
    sym_p3 = 3

    # compare cases left to rigth
    assert (board.win_diag_slash(test_pos_1[0][0], test_pos_1[0][1], True,
                                 sym_p1) < size_line)
    assert (board.win_diag_slash(test_pos_1[1][0], test_pos_1[1][1], True,
                                 sym_p1) < size_line)
    assert (board.win_diag_slash(test_pos_1[2][0], test_pos_1[2][1], True,
                                 sym_p2) < size_line)
    assert (board.win_diag_slash(test_pos_1[3][0], test_pos_1[3][1], True,
                                 sym_p2) < size_line)
    assert (board.win_diag_slash(test_pos_1[4][0], test_pos_1[4][1], True,
                                 sym_p1) < size_line)
    assert (board.win_diag_slash(test_pos_1[5][0], test_pos_1[5][1], True,
                                 sym_p1) < size_line)
    # compare cases rigth to left
    assert (board.win_diag_slash(test_pos_2[0][0], test_pos_2[0][1], False,
                                 sym_p2) < size_line)
    assert (board.win_diag_slash(test_pos_2[1][0], test_pos_2[1][1], False,
                                 sym_p2) < size_line)
    assert (board.win_diag_slash(test_pos_2[2][0], test_pos_2[2][1], False,
                                 sym_p1) < size_line)
    assert (board.win_diag_slash(test_pos_2[3][0], test_pos_2[3][1], False,
                                 sym_p1) < size_line)
    assert (board.win_diag_slash(test_pos_2[4][0], test_pos_2[4][1], False,
                                 sym_p1) < size_line)
    assert (board.win_diag_slash(test_pos_2[5][0], test_pos_2[5][1], False,
                                 sym_p1) < size_line)
    # compare with symbol not valid
    assert (board.win_diag_slash(test_pos_1[4][0], test_pos_1[4][1], True,
                                 sym_p3) < size_line)
    assert (board.win_diag_slash(test_pos_1[5][0], test_pos_1[5][1], True,
                                 sym_p3) < size_line)
    assert (board.win_diag_slash(test_pos_2[0][0], test_pos_2[0][1], False,
                                 sym_p3) < size_line)
    assert (board.win_diag_slash(test_pos_2[1][0], test_pos_2[1][1], False,
                                 sym_p3) < size_line)
    # compare with cell (row, col) not valid
    assert (board.win_diag_slash(test_pos_3[0][0], test_pos_3[0][1], True,
                                 sym_p3) < size_line)
    assert (board.win_diag_slash(test_pos_3[1][0], test_pos_3[1][1], True,
                                 sym_p3) < size_line)
    assert (board.win_diag_slash(test_pos_3[2][0], test_pos_3[2][1], False,
                                 sym_p3) < size_line)
    assert (board.win_diag_slash(test_pos_3[3][0], test_pos_3[3][1], False,
                                 sym_p3) < size_line)
Ejemplo n.º 4
0
 def __init__(self, player_1, player_2):
     self.board = Board()
     self.player_1 = player_1
     self.player_2 = player_2
     self.turn_player_1 = False