Example #1
0
 def test_full_board(self):
     board = Board()
     board_service = BoardService(board)
     for x in range(7):
         for y in range(6):
             board.set_position(x, y, 1)
     self.assertEqual(board_service.game_state(), 0)
Example #2
0
 def test_board_create(self):
     board = Board()
     self.assertEqual(board.win(), None)
     self.assertEqual(board.tie(), False)
     for row in range(15):
         for col in range(15):
             self.assertEqual(board.get_square(row, col), 0)
Example #3
0
 def test_menu_exception(self):
     board = Board()
     board_service = BoardService(board)
     ai = AI(board)
     ui = UI(board_service, ai)
     with patch('builtins.input', side_effect='0'):
         self.assertRaises(MenuException, lambda: ui.menu())
Example #4
0
 def test_algorithm(self):
     board = Board()
     algortihm = AlgorithmSimple()
     self.assertEqual(algortihm.next_move(board), (0, 0))
     board.move(0, 0, 'b')
     self.assertEqual(algortihm.next_move(board), (0, 1))
     board.move(0, 1, 'b')
     self.assertEqual(algortihm.next_move(board), (0, 2))
Example #5
0
 def test_board_win(self):
     board = Board()
     board.move(1, 1, 'b')
     board.move(1, 5, 'b')
     board.move(1, 4, 'b')
     board.move(1, 3, 'b')
     board.move(1, 2, 'b')
     self.assertEqual(board.win(), 5)
Example #6
0
 def test_ai(self):
     board = Board()
     ai = AI(board)
     board.set_position(0, 5, 1)
     board.set_position(1, 5, 1)
     board.set_position(2, 5, 1)
     board.set_position(3, 5, 1)
     board.set_position(4, 5, 1)
     board.set_position(5, 5, 1)
     self.assertIsInstance(ai.generator(), int)
Example #7
0
 def test_board_domain(self):
     board = Board()
     for x in range(7):
         for y in range(6):
             self.assertEqual(
                 board.get_position(x, y), 0,
                 "Board is not initialised with 0, error is located at: %s, %s"
                 % (x, y))
     board.set_position(1, 0, 1)
     self.assertEqual(board.get_position(1, 0), 1,
                      "set_position not working for Board")
Example #8
0
 def test_diagonal(self):
     board = Board()
     board_service = BoardService(board)
     board.set_position(0, 0, 1)
     board.set_position(1, 1, 1)
     board.set_position(2, 2, 1)
     board.set_position(3, 3, 1)
     self.assertEqual(board_service.game_state(), 1)
     board.set_position(2, 2, 0)
     board.set_position(6, 0, 1)
     board.set_position(5, 1, 1)
     board.set_position(4, 2, 1)
     board.set_position(3, 3, 1)
     self.assertEqual(board_service.game_state(), 1)
Example #9
0
 def test_board_service_add_piece_and_exceptions(self):
     board = Board()
     board_service = BoardService(board)
     self.assertEqual(
         board_service.show,
         '0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 \n',
         "This shouldn't not work anymore")
     board_service.add_piece(1, 1)
     self.assertEqual(board.get_position(1, 0), 1, "add_piece not working")
     # Testing column full exception
     board_service.add_piece(1, 1)
     board_service.add_piece(1, 1)
     board_service.add_piece(1, 1)
     board_service.add_piece(1, 1)
     board_service.add_piece(1, 1)
     self.assertRaises(ServiceException,
                       lambda: board_service.add_piece(1, 1))
Example #10
0
 def __init__(self):
     self.board = Board()
Example #11
0
 def test_board_move(self):
     board = Board()
     board.move(1, 1, 'b')
     self.assertEqual(board.get_square(1, 1), 1)
Example #12
0
 def test_y_axis(self):
     board = Board()
     board_service = BoardService(board)
     for y in range(1, 5):
         board_service.add_piece(1, 1)
     self.assertEqual(board_service.game_state(), 1)
 def setUp(self):
     self.repo = Board()
Example #14
0
from ai import AI
from domain import Board
from menu import UI
from service import BoardService

board = Board()
board_service = BoardService(board)
ai = AI(board)
ui = UI(board_service, ai)
ui.menu()
Example #15
0
 def __init__(self):
     self.__board = Board(6, 6).getBoard()
     # the next list represents the directions: up, down, right, left and every diagonal
     self.__directions = [(0, -1), (-1, -1), (-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1)]
     self.__usedCells = []  # the list that keeps the occupied cells
Example #16
0
from Ui import UserInterface


class Game:
    '''
    This comunicates with the domain layer
    '''
    def __init__(self, board):
        self.__board = board

    def makeMoveAi(self):
        return self.__board.makeMoveAi()

    def makeMovePlayer(self, point):
        return self.__board.makeMovePlayer(point)

    def __str__(self):
        return str(self.__board)

    def verifyWinPlayer(self):
        return self.__board.verifyWinPlayer()

    def checkWin(self):
        return self.__board.checkWin()


GameBoard = Board()
Gm = Game(GameBoard)
ui = UserInterface(Gm)
ui._start()
Example #17
0
 def __init__(self, height, width, bombs):
     self.__mainBoard = Board(height, width, bombs)
     self.__visited = [[0 for i in range(width)] for j in range(height)]
     self.__flags = [[0 for i in range(width)] for j in range(height)]
     self.__mainBoard.fillBoardWithBombs()
     self.__mainBoard.fillBoardNumbers()
Example #18
0
    def start(self):
        inp = 0
        moves = 0
        winner_found = False
        #if inp % 2 == 0 user have to add a new value, if inp % 2 != 0 the computer will play
        while winner_found == False and moves != 42:
            try:
                self.display_board()
                if inp % 2 == 0:
                    q = self.user_move()
                    while q == 0:
                        q = self.user_move()
                    moves = moves + 1
                else:
                    q = self.computer_move()
                    while q == 0:
                        q = self.computer_move()
                    moves = moves + 1
                if self.check_for_winner(winner_found) == 1:
                    print(self.service.table_value())
                    return
            except IndexError as m:
                print(m)
            except ValueError as m:
                print(m)
            inp = inp + 1
b = Board()
s = Service(b)
u = UI(s)
u.start()