-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bot_Random.py
88 lines (70 loc) · 2 KB
/
Bot_Random.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
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 22 11:43:54 2015
@author: Ralf Engelken, Franziska Neu
"""
import random
class Bot:
info = None
def __init__(self):
self.bot_name = "Bot"
pass
def new_game(self):
pass
def get_action(self, world):
x = 0
y = 0
return (x, y)
def evaluate_action(self, world_new):
pass
"""
Loads
"""
def load_data(self, filename):
raise NotImplementedError
"""
Saves
"""
def save_data(self, filename):
raise NotImplementedError
"""
On Generatino, this bot generates a random order in which he places stones on the field.
Afterwards, he always places a stone on the first free field in this order
"""
class Bot_Random_Static (Bot):
def __init__(self, size_x, size_y):
Bot.__init__(self)
self.bot_name = "Bot_Random_Static"
#Generate random order
self.order = []
for i in range(size_x * size_y):
self.order.append(i)
random.shuffle(self.order)
def get_action(self, world):
i = 0
act = self.order[i]
x = act % world.size_x
y = act / world.size_y
while (world.check_action(x, y) == False):
i += 1
act = self.order[i]
x = act % world.size_x
y = act / world.size_y
x = act % world.size_x
y = act / world.size_y
return (x, y)
"""
This bot always places a stone on a random field
"""
class Bot_Random_Dynamic (Bot):
def __init__(self, size_x, size_y):
Bot.__init__(self)
self.bot_name = "Bot_Random_Dynamic"
def get_action(self, world):
if (world.get_sensor_info() == None):
x = 0
y = 0
else:
x = random.randint(0, world.size_x - 1)
y = random.randint(0, world.size_y - 1)
return (x, y)