MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / get_state

Method get_state

rl/tic_tac_toe.py:156–174  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

154 return 1 if self.winner == sym else 0
155
156 def get_state(self):
157 # returns the current state, represented as an int
158 # from 0...|S|-1, where S = set of all possible states
159 # |S| = 3^(BOARD SIZE), since each cell can have 3 possible values - empty, x, o
160 # some states are not possible, e.g. all cells are x, but we ignore that detail
161 # this is like finding the integer represented by a base-3 number
162 k = 0
163 h = 0
164 for i in range(LENGTH):
165 for j in range(LENGTH):
166 if self.board[i,j] == 0:
167 v = 0
168 elif self.board[i,j] == self.x:
169 v = 1
170 elif self.board[i,j] == self.o:
171 v = 2
172 h += (3**k) * v
173 k += 1
174 return h
175
176 def game_over(self, force_recalculate=False):
177 # returns true if game over (a player has won or it's a draw)

Callers 3

take_actionMethod · 0.80
play_gameFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected