Exemple #1
0
 def test_onePieceInJailNegPlayer(self):
     self.board.setDefaultBoardState()
     initialState = [9999,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-9999]
     self.board.clearErrors()
     self.board.setCustomBoardState(copy.deepcopy(initialState), -1)
     self.board.setDiceRoll([1,2])
     engine = BGEngine(copy.deepcopy(self.board))
     engine.addDice(copy.deepcopy(self.board.getActiveDice()))
     move = engine.getMoveForPlayer(-1)
     self.assertEqual(move,[('jail',1),(1,3)])
Exemple #2
0
 def test_getMovesReturnsFalse(self):
     self.board.setDefaultBoardState()
     initialState = [9999,1,0,0,0,0,0,0,5,0,3,1,0,0,-4,4,1,0,-1,-4,-1,-5,0,0,0,0,0,0,0,-9999]
     self.board.clearErrors()
     self.board.setCustomBoardState(copy.deepcopy(initialState), 1)
     self.board.setDiceRoll([2,6])
     engine = BGEngine(copy.deepcopy(self.board))
     engine.addDice(copy.deepcopy(self.board.getActiveDice()))
     move = engine.getMoveForPlayer(1)
     self.assertEqual(move,[('jail',23),(14,8)])
Exemple #3
0
 def test_onePieceToMove(self):
     self.board.setDefaultBoardState()
     initialState = [9999,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-9999]
     self.board.clearErrors()
     self.board.setCustomBoardState(copy.deepcopy(initialState), 1)
     self.board.setDiceRoll([1,2])
     self.assertEqual(self.board.board,initialState)
     engine = BGEngine(copy.deepcopy(self.board))
     engine.addDice(copy.deepcopy(self.board.getActiveDice()))
     move = engine.getMoveForPlayer(1)
     self.assertEqual(move,[(10,9),(9,7)])
Exemple #4
0
 def test_getMovesReturnsFalse(self):
     self.board.setDefaultBoardState()
     initialState = [
         9999, 1, 0, 0, 0, 0, 0, 0, 5, 0, 3, 1, 0, 0, -4, 4, 1, 0, -1, -4,
         -1, -5, 0, 0, 0, 0, 0, 0, 0, -9999
     ]
     self.board.clearErrors()
     self.board.setCustomBoardState(copy.deepcopy(initialState), 1)
     self.board.setDiceRoll([2, 6])
     engine = BGEngine(copy.deepcopy(self.board))
     engine.addDice(copy.deepcopy(self.board.getActiveDice()))
     move = engine.getMoveForPlayer(1)
     self.assertEqual(move, [('jail', 23), (14, 8)])
Exemple #5
0
 def test_onePieceInJailNegPlayer(self):
     self.board.setDefaultBoardState()
     initialState = [
         9999, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, -1, -9999
     ]
     self.board.clearErrors()
     self.board.setCustomBoardState(copy.deepcopy(initialState), -1)
     self.board.setDiceRoll([1, 2])
     engine = BGEngine(copy.deepcopy(self.board))
     engine.addDice(copy.deepcopy(self.board.getActiveDice()))
     move = engine.getMoveForPlayer(-1)
     self.assertEqual(move, [('jail', 1), (1, 3)])
Exemple #6
0
 def test_onePieceToMove(self):
     self.board.setDefaultBoardState()
     initialState = [
         9999, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, -9999
     ]
     self.board.clearErrors()
     self.board.setCustomBoardState(copy.deepcopy(initialState), 1)
     self.board.setDiceRoll([1, 2])
     self.assertEqual(self.board.board, initialState)
     engine = BGEngine(copy.deepcopy(self.board))
     engine.addDice(copy.deepcopy(self.board.getActiveDice()))
     move = engine.getMoveForPlayer(1)
     self.assertEqual(move, [(10, 9), (9, 7)])
Exemple #7
0
    def gameLoop(self):
        random.seed();
        dice = self.doDiceRoll()
        self.board.setDiceRoll(copy.deepcopy(dice))
        self.setupBoardView()
        self.boardView.addPromptText('(h)uman; (c)omputer; (t)est; (q)uit?> ')
        testing = False
        computer = False
        human = False

        while True:
            self.setupBoardView()
            inputStr = self.boardView.getUserInput().decode('ascii').strip()
            if inputStr in ['c', 'C']:
                computer = True
                break
            elif inputStr in ['h', 'H']:
                human = True
                break
            elif inputStr in ['t', 'T']:
                testing = True
                break
            elif inputStr in ['q', 'Q']:
                self.cleanUpCurses()
                return True
            else:
                self.boardView.addPromptText('(h)uman; (c)omputer; (t)est; (q)uit?> ')
        self.boardView.addPromptText(False)
        self.setupBoardView()

        while True:
            if not self.board.playerHasMoveAvailable():
                self.boardView.addErrorMessage('Player {0} has no moves available with dice {1},{2}!'\
                                                .format(self.boardView.returnViewPlayerFromBoardPlayer(self.board.getTurn()), dice[0], dice[1] ))
                logging.debug('No move for {0}'.format(self.board.getTurn()))
                self.board.toggleTurn()
                dice = self.doDiceRoll()
                self.board.setDiceRoll(copy.deepcopy(dice))
                self.board.clearErrors()
                self.setupBoardView()
                continue

            if self.board.getTurn() == 1:
                if testing:
                    bgEngine = BGEngine(copy.deepcopy(self.board))
                    bgEngine.addDice(copy.deepcopy(self.board.getActiveDice()))
                    move = bgEngine.getMoveForPlayer(self.board.getTurn())
                    if not move:
                        logging.debug('FAIL getting move for board {0} for player {1} with dice {2}'.format(",".join(str(x) for x in self.board.board), str(self.board.getTurn()), dice))
                        import pdb; pdb.set_trace()
                    error = self.doComputerMove(move, dice, testing)
                else:
                    error = self.doHumanMove()
            else:
                if human :
                    error = self.doHumanMove()
                elif computer or testing:
                    if not testing:
                        sleep(1)
                    bgEngine = BGEngine(copy.deepcopy(self.board))
                    bgEngine.addDice(copy.deepcopy(self.board.getActiveDice()))
                    move = bgEngine.getMoveForPlayer(self.board.getTurn())
                    if not move:
                        logging.debug('FAIL getting move for board {0} for player {1} with dice {2}'.format(",".join(str(x) for x in self.board.board), str(self.board.getTurn()), dice))
                        import pdb; pdb.set_trace()
                    error = self.doComputerMove(move, dice,testing)

            if not error and self.board.gameIsOver():
                self.boardView.addErrorMessage(self.board.getRecentError())
                self.board.clearErrors()
                self.boardView.addState(self.board.getBoardState())
                self.boardView.createBoard(self.board.getTurn())
                return True

            if not error and self.board.turnIsOver():
                self.board.toggleTurn()
                dice = self.doDiceRoll()
                self.board.setDiceRoll(copy.deepcopy(dice))
                self.boardView.addDice(copy.deepcopy(dice))

            self.board.clearErrors()
            self.setupBoardView(dice)