コード例 #1
0
 def test_minimax(self):
     """Test a bad move"""
     game = ttt.Game()
     game.current_user = '******'
     game.player_board = [1, 2]
     game.player_board = [5, 9, 4]
     game.computer_token = 'O'
     game.player_token = 'X'
     game.open_moves = range(2, 10)
     self.assertEqual(ttt.minimax(game), -1)
コード例 #2
0
 def test_find_best_move(self):
     """Should return best move"""
     game = ttt.Game()
     game.current_user = '******'
     game.player_board = [1]
     game.computer_board = []
     game.computer_token = 'O'
     game.player_token = 'X'
     game.open_moves = range(2, 10)
     self.assertEqual(ttt.find_best_move(game, take_five=False), 5)
コード例 #3
0
def main(argv):
    configs = (
        (ttt_player.APlayer(ttt.Board.default_p1),
         ttt_player.APlayer(ttt.Board.default_p2)),
        (ttt_player.APlayer(ttt.Board.default_p1),
         ttt_player.ADPlayer(ttt.Board.default_p2)),
        (ttt_player.APlayer(ttt.Board.default_p1),
         ttt_player.DPlayer(ttt.Board.default_p2)),
        (ttt_player.ADPlayer(ttt.Board.default_p1),
         ttt_player.APlayer(ttt.Board.default_p2)),
        (ttt_player.ADPlayer(ttt.Board.default_p1),
         ttt_player.ADPlayer(ttt.Board.default_p2)),
        (ttt_player.ADPlayer(ttt.Board.default_p1),
         ttt_player.DPlayer(ttt.Board.default_p2)),
        (ttt_player.DPlayer(ttt.Board.default_p1),
         ttt_player.APlayer(ttt.Board.default_p2)),
        (ttt_player.DPlayer(ttt.Board.default_p1),
         ttt_player.ADPlayer(ttt.Board.default_p2)),
        (ttt_player.DPlayer(ttt.Board.default_p1),
         ttt_player.DPlayer(ttt.Board.default_p2)),
    )
    configs = (
        (ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95}),
         ttt_player.DRPlayer(ttt.Board.default_p2)),
        (ttt_player.DRPlayer(ttt.Board.default_p1),
         ttt_player.DRPlayer(ttt.Board.default_p2, params={'dr': 0.95})),
    )
    configs = (
        (ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95}),
         ttt_player.APlayer(ttt.Board.default_p2)),
        (ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.9}),
         ttt_player.ADPlayer(ttt.Board.default_p2)),
        (ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95}),
         ttt_player.DPlayer(ttt.Board.default_p2)),
        (ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95}),
         ttt_player.DRPlayer(ttt.Board.default_p2)),
        (ttt_player.APlayer(ttt.Board.default_p2),
         ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95})),
        (ttt_player.ADPlayer(ttt.Board.default_p2),
         ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95})),
        (ttt_player.DPlayer(ttt.Board.default_p2),
         ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95})),
        (ttt_player.DRPlayer(ttt.Board.default_p2),
         ttt_player.DRPlayer(ttt.Board.default_p1, params={'dr': 0.95})),
    )

    res = []
    for idx, config in enumerate(configs):
        res.append({None: 0, ttt.Board.default_p1: 0, ttt.Board.default_p2: 0})
        for exper in range(0, 10):
            g = ttt.Game(config[0], config[1])
            g.start()
            res[idx][g.b.who_won()] += 1
        print('%s, %s vs %s' % (res[idx], config[0].name, config[1].name))
コード例 #4
0
ファイル: main.py プロジェクト: markjc/cli-games
def runGame(userInput):
    ### Take user input and Map it to a runnable game - then engage that class
    if userInput == 1:
        #Run Game 1: Rock Paper Scissors
        newGame = rps.Game()
        newGame.intro()
        newGame.gameLoop()
        mainMenu()
    elif userInput == 2:
        #Run Game 2: Tic - Tac - Toe
        newGame = ttt.Game()
        newGame.intro()
        newGame.gameLoop()
        mainMenu()
    elif userInput == 3:
        #Run Game 3: Number Guessing Game
        newGame = ngg.Game()
        newGame.intro()
        newGame.gameLoop()
        mainMenu()
    elif userInput == 4:
        sys.exit()
    else:
        mainMenu()
コード例 #5
0
 def test_draw_board(self):
     """Printable board should be returned"""
     game = ttt.Game()
     test_board = '1 2 3 \n4 5 6 \n7 8 9 '
     self.assertEqual(ttt.draw_board(game), test_board)
コード例 #6
0
 def setUp(self):
     self.game = ttt.Game()