forked from ericyd/2048
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (33 loc) · 1.22 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
sys.path.append('./lib')
from human import Human
from bot import Bot
import operator
player_type = input("are you human? (y/n): ")
if player_type.strip() == 'y':
player = Human()
(highest_tile, score) = player.play()
else:
player = Bot('quiet') # pass 'verbose' to print detailed info after each move
# get number of games to play
number_of_games = input("how many games would you like to play? (default: 100) ")
try:
int(number_of_games)
except:
number_of_games = 100
# get strategy to play with
strategy = input("what strategy would you like to use? (enter a number)\n{} \n".format(player.list_strategies()))
strategy = player.set_strategy(strategy)
# play number of games with desired strategy
print("playing {} games with '{}' strategy".format(number_of_games, strategy))
tiles = []
for i in range(int(number_of_games)):
print('playing game {}'.format(i + 1))
tiles.append(player.play())
# get highest score from all the games played
highest = max(tiles, key=operator.itemgetter('score'))
highest_tile = highest['highest_tile']
score = highest['score']
board = highest['board']
player.display(board)
print("score = {} | highest tile {}".format(score, highest_tile))