-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
94 lines (72 loc) · 2.89 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import random
from typing import Dict, List, Tuple
from check_submission import check_submission
from game_mechanics import (
Cell,
WildTictactoeEnv,
choose_move_randomly,
load_dictionary,
play_wild_ttt_game,
render,
save_dictionary,
)
TEAM_NAME = "Memes" # <---- Enter your team name here!
assert TEAM_NAME != "Team Name", \
"Please change your TEAM_NAME!"
def train() -> Dict:
"""Write this function to train your algorithm.
Returns:
Value function dictionary used by your agent. You can
structure this how you like, however your choose_move must
be able to use it.
"""
raise NotImplementedError("You need to implement this function!")
def choose_move(board: List[str], value_function: Dict) -> Tuple[int, str]:
"""
TODO: WRITE THIS FUNCTION
This is what will be called during competitive play.
It takes the current state of the board as input.
It returns a single move to play.
Args:
board: list representing the board.
(see README Technical Details for more info)
value_function: The dictionary output by train().
Returns:
position (int): The position to place your piece
(an integer 0 -> 8), where 0 is
top left and 8 is bottom right.
counter (str): The counter to place. "X" or "O".
It's important that you think about exactly what this
function does when you submit, as it will be called
in order to take your turn!
"""
# We provide an example here that chooses a random position on the board and
# and places a random counter there.
# position = random.choice([count for count, item in enumerate(board) if item == Cell.EMPTY])
# counter = random.choice([Cell.O, Cell.X])
# return position, counter
raise NotImplementedError("You need to implement this function!")
if __name__ == "__main__":
## Example workflow, feel free to edit this! ###
my_value_fn = train()
save_dictionary(my_value_fn, TEAM_NAME)
my_value_fn = load_dictionary(TEAM_NAME)
def choose_move_no_value_fn(board: List[str]) -> Tuple[int, str]:
"""
The arguments in play_wild_ttt_game() require functions
that only take the state as input.
This converts choose_move() to that format.
"""
return choose_move(board, my_value_fn)
# Code below plays a single game of Wild Tic-Tac-Toe vs a random
# opponent, think about how you might want to adapt this to
# test the performance of your algorithm.
# total_return = play_wild_ttt_game(
# your_choose_move=choose_move_no_value_fn,
# opponent_choose_move=choose_move_randomly,
# game_speed_multiplier=1,
# verbose=True,
# )
# Below renders a game graphically. You must click to take turns
render(choose_move_no_value_fn)
check_submission()