class Test(unittest.TestCase): def setUp(self): unittest.TestCase.setUp() self.b=Board() def tearDown(self): unittest.TestCase.tearDown() def testdat(self): self.assertEqual(self.b.getPC(),[[0]*8, [0]*8 ,[0]*8 ,[0]*8 ,[0]*8 ,[0]*8 ,[0]*8 ,[0]*8]) self.assertEqual(self.b.getPlayer(),[[0]*8, [0]*8 ,[0]*8 ,[0]*8 ,[0]*8 ,[0]*8 ,[0]*8 ,[0]*8])
def __init__(self): """ Constructor of the game controller class. """ self.__playerBoard = Board(8, 8).getMatrix() self.__computerBoard = Board(8, 8).getMatrix() self.__hitBoard = Board(8, 8).getMatrix() self.__computerPlanes = [] self.__playerPlanes = [] self.__computerMoves = [(0, 0), (0, 7), (7, 0), (7, 7)] self.__neighboursQueue = [] self.addComputerPlanes()
def test_board_set_mines(fake_repo): """Test to set mines in a board""" rows = cols = mines = 8 game_factory = GameFactory(fake_repo) board_payload = dict(rows=rows, cols=cols) initial_slots = game_factory._get_initial_slots(**board_payload) board = Board(id=str(uuid4()), slots=initial_slots, **board_payload) board.set_mines(mines) count_mines = 0 for row in board.slots: for slot in row: if slot.mine: count_mines += 1 assert count_mines == mines
def update(self, nTimes=1): ''' Updates the tables status of nTimes by default being 1 using given rules input: nTimes - integer ''' newSt = Board() while nTimes > 0: nTimes -= 1 for i in range(8): for j in range(8): nei = self.getNbOfNei(Square(i, j)) if nei == 2 or nei == 3: newSt.board[i][j] = 'x' if self._board.board[i][j] == '0' and nei == 3: newSt.board.board[i][j] = 'x' self._board = deepcopy(newSt)
def test_new_board(): """Test to create a new board with slots initialized""" rows = cols = 8 board = Board(id=str(uuid4()), rows=rows, cols=cols) for row in board.slots: for slot in row: assert slot.available is True assert slot.mine is False
def testPlaneValidation(self): from domain.board import Board p = Plane(0, 'up') b = Board(8, 8).getMatrix() with self.assertRaises(PlaneError): PlaneValidator.validate(p, b) p = Plane((2, 0), 'left') self.assertIsNone(PlaneValidator.validate(p, b)) p = Plane((0, -1), 'down') with self.assertRaises(PlaneError): PlaneValidator.validate(p, b) p = Plane((2, 0), 'right') with self.assertRaises(PlaneError): PlaneValidator.validate(p, b)
def build_board(player_name): players = {} character = character_service.find_character(player_name) user = Character(character.attrib.get('name'), pos=0, token='<', attack=int(character[1].text), defense=int(character[2].text), speed=int(character[3].text), endurance=int(character[4].text), health=int(character[0].text), strategy='', team=character[5].text) players[user.name] = user level = find_level("1") dim = int(level[0].text) # dim multiplier = int(level[2].text) # koobas multiplier counter = 0 grunt_xml = character_service("grunt") print(grunt_xml[5].text) while counter < int(level[1].text): # koombas location = random.randint(1, dim*dim-1) koomba = Character("koomba" + str(counter), location, 'V', int(grunt_xml[1].text)*multiplier, int(grunt_xml[2].text)*multiplier, int(grunt_xml[3].text)*multiplier, int(grunt_xml[4].text)*multiplier, int(grunt_xml[0].text)*multiplier, 'aggressive', grunt_xml[5].text) players[koomba.name] = koomba counter += 1 board = Board(dim, dim) # 'player4': player4, 'player5': player5} board.update(players) # board.print_board() return [board, players]
def start(self, player: Player) -> Game: """Prepare the board and start the game""" board_payload = dict(rows=self.rows, cols=self.cols) initial_slots = self._get_initial_slots(**board_payload) board_db = self.repo.boards.add({ **board_payload, "slots": initial_slots, "mines": 0 }) board = Board.from_orm(board_db) board.set_mines(mines=self.mines) board_db = self.repo.boards.update(board_db, board) game_payload = dict( player_id=player.id, board_id=board.id, status=GameStatusEnum.ongoing, start_time=datetime.utcnow(), ) game_db = self.repo.games.add(game_payload) game = Game.from_orm(game_db) return game
def testGetComputerBoard(self): self.srv.resetGame() self.assertEqual(type(self.srv.getComputerBoard()), type(Board(8, 8).getMatrix()))
def testGetMatrix(self): matrix = Board(1, 2, '0').getMatrix() self.assertEqual(matrix, [['0'], ['0']]) matrix = Board(3, 2).getMatrix() self.assertEqual(matrix, [[' ', ' ', ' '], [' ', ' ', ' ']])
def computerMoveTest(): v = BoardValidator() b = Board(v) b.placePlayerPart(0, 0) b.placePlayerPart(0, 1) b.placePlayerPart(0, 2) b.placePlayerPart(0, 3) b.computerPart() assert b.getData(0, 4) == 1 b.placePlayerPart(1, 0) b.placePlayerPart(1, 1) b.placePlayerPart(1, 2) b.placePlayerPart(1, 3) b.computerPart() assert b.getData(1, 4) == 1 b.computerPart() s = 0 for i in range(0, 6): for j in range(0, 6): s = s + b.getData(i, j) assert s == 8 * 2 + 3
def __init__(self): self._plBoard = Planes_Board(board=Board(), player=1) self._aiBoard = Planes_Board(board=Board(), player=0)
def __init__(self): self.__strategy_board = Board() self.__targeting_board = Board() self.__planes_coordinates = []
def set_targeting_board(self, targeting_board=None): if targeting_board is None: targeting_board = Board() self.__targeting_board = targeting_board
def set_strategy_board(self, strategy_board=None): if strategy_board is None: strategy_board = Board() self.__strategy_board = strategy_board
def testGetHitBoard(self): self.srv.resetGame() self.assertEqual(self.srv.getHitBoard(), Board(8, 8).getMatrix())
def setUp(self): self.ai = Planes_Board(board=Board()) self.pl = Planes_Board(board=Board(), player=1)
from domain.board import Board from validators.boardvalidator import BoardValidator from game.gameUI import Game v = BoardValidator() b = Board(v) g = Game(b) g.getUserInput()
def setUp(self): unittest.TestCase.setUp() self.b=Board()
def __init__(self): self._board = Board()