-
Notifications
You must be signed in to change notification settings - Fork 0
/
bots.py
executable file
·118 lines (95 loc) · 3.21 KB
/
bots.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python
import numpy as np
from bot_algorithms.alpha_beta_custom_voronoi import alpha_beta_custom_voronoi
from bot_algorithms.alpha_beta_cutoff import alpha_beta_cutoff
from bot_algorithms.voronoi_heuristic import *
from tronproblem import *
from trontypes import CellType, PowerupType
import random, math
cutoff = 9
class StudentBot:
""" Write your student bot here"""
def decide(self, asp):
"""
Input: asp, a TronProblem
Output: A direction in {'U','D','L','R'}
To get started, you can get the current
state by calling asp.get_start_state()
"""
# direction = alpha_beta_cutoff2(asp, 5)
direction = alpha_beta_cutoff(asp, cutoff, voronoi_v3)
return direction
def cleanup(self):
"""
Input: None
Output: None
This function will be called in between
games during grading. You can use it
to reset any variables your bot uses during the game
(for example, you could use this function to reset a
turns_elapsed counter to zero). If you don't need it,
feel free to leave it as "pass"
"""
pass
def cleanup(self):
"""
Input: None
Output: None
This function will be called in between
games during grading. You can use it
to reset any variables your bot uses during the game
(for example, you could use this function to reset a
turns_elapsed counter to zero). If you don't need it,
feel free to leave it as "pass"
"""
pass
class RandBot:
"""Moves in a random (safe) direction"""
def decide(self, asp):
"""
Input: asp, a TronProblem
Output: A direction in {'U','D','L','R'}
"""
state = asp.get_start_state()
locs = state.player_locs
board = state.board
ptm = state.ptm
loc = locs[ptm]
possibilities = list(TronProblem.get_safe_actions(board, loc))
if possibilities:
return random.choice(possibilities)
return "U"
def cleanup(self):
pass
class WallBot:
"""Hugs the wall"""
def __init__(self):
order = ["U", "D", "L", "R"]
random.shuffle(order)
self.order = order
def cleanup(self):
order = ["U", "D", "L", "R"]
random.shuffle(order)
self.order = order
def decide(self, asp):
"""
Input: asp, a TronProblem
Output: A direction in {'U','D','L','R'}
"""
state = asp.get_start_state()
locs = state.player_locs
board = state.board
ptm = state.ptm
loc = locs[ptm]
possibilities = list(TronProblem.get_safe_actions(board, loc))
if not possibilities:
return "U"
decision = possibilities[0]
for move in self.order:
if move not in possibilities:
continue
next_loc = TronProblem.move(loc, move)
if len(TronProblem.get_safe_actions(board, next_loc)) < 3:
decision = move
break
return decision