-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_codebreaker.py
38 lines (30 loc) · 982 Bytes
/
random_codebreaker.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
import random as rand
import time
from codemaker import LENGTH_OF_CODE
class RandomCodeBreaker:
"""
Random CodeBreaker generates the moves to guess
the code designed by CodeMaker. There are no repetitions allowed
in the move, and every move is to be of fixed length.
Moves are generated randomly without any due regard to the feedback
generated by the code-maker, or the knowledge model maintained in
the game.
"""
def get_first_move(self):
self.move = generate_random_move()
return self.move
def get_next_move(self, feedback):
self.move = generate_random_move()
return self.move
def generate_random_move():
"""
Generates a random move
"""
move = []
available_choices = [1, 2, 3, 4, 5, 6]
rand.seed(time.time_ns())
for _ in range(0, LENGTH_OF_CODE):
val = rand.choice(available_choices)
move.append(val)
available_choices.remove(val)
return move