updates
This commit is contained in:
parent
68b2d193c8
commit
5449cc2a25
|
@ -22,4 +22,4 @@ Card lists can be found at the following 2 images:
|
||||||
|
|
||||||
If there are no legal moves left in the game, check number of tokens held by each player. Highest banner token player wins.
|
If there are no legal moves left in the game, check number of tokens held by each player. Highest banner token player wins.
|
||||||
|
|
||||||
See my previous python implementation of the game at https://raw.githubusercontent.com/captn3m0/gothok
|
See my previous python implementation of the game at https://github.com/captn3m0/gothok/
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
import capnp
|
import capnp
|
||||||
import state_capnp as game
|
import state_capnp as game
|
||||||
|
|
||||||
|
# https://blog.theofekfoundation.org/artificial-intelligence/2016/06/27/what-is-the-monte-carlo-tree-search/
|
||||||
|
|
||||||
|
|
||||||
class State():
|
class State():
|
||||||
|
|
||||||
|
@ -20,6 +22,34 @@ class State():
|
||||||
self.initBoard()
|
self.initBoard()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def playMove(self, move):
|
||||||
|
(xx, yy) = move
|
||||||
|
|
||||||
|
varys = self.findVarys
|
||||||
|
vx = varys.board.x
|
||||||
|
vy = varys.board.y
|
||||||
|
|
||||||
|
if (vx == xx):
|
||||||
|
left = min(yy, vy)
|
||||||
|
right = max(yy, vy)
|
||||||
|
# We want this to be inclusive
|
||||||
|
cards_attempted = [(vx, y) for y in range(left, right + 1)]
|
||||||
|
elif(vy == yy):
|
||||||
|
top = min(xx, vx)
|
||||||
|
bottom = max(xx, vx)
|
||||||
|
# We want this to be inclusive
|
||||||
|
cards_attempted = [(x, vy) for x in range(top, bottom + 1)]
|
||||||
|
else:
|
||||||
|
raise Exception("Invalid move")
|
||||||
|
|
||||||
|
for (row, col) in cards_attempted:
|
||||||
|
card = self.board[row][col]
|
||||||
|
# If it is of the same house as declared
|
||||||
|
if (card == picked_card):
|
||||||
|
# Pick it up
|
||||||
|
state['cards'][current].append(picked_card)
|
||||||
|
state['board'][row][col] = self.EMPTY
|
||||||
|
|
||||||
def findVarys(self):
|
def findVarys(self):
|
||||||
for card in self.state.cardlist:
|
for card in self.state.cardlist:
|
||||||
if card.house == 'varys':
|
if card.house == 'varys':
|
||||||
|
@ -30,7 +60,6 @@ class State():
|
||||||
|
|
||||||
for x in range(0, 5):
|
for x in range(0, 5):
|
||||||
for y in range(0, 5):
|
for y in range(0, 5):
|
||||||
|
|
||||||
if (self.isLegalMoveLocation(x, y)):
|
if (self.isLegalMoveLocation(x, y)):
|
||||||
moves.append((x, y))
|
moves.append((x, y))
|
||||||
|
|
||||||
|
@ -118,7 +147,7 @@ class GameNode(object):
|
||||||
while not state.gameOver:
|
while not state.gameOver:
|
||||||
moves = state.getPossibleMoves()
|
moves = state.getPossibleMoves()
|
||||||
randomMove = random.choice(possibleMoves)
|
randomMove = random.choice(possibleMoves)
|
||||||
state.playMove(randomMove)
|
state = state.playMove(randomMove)
|
||||||
|
|
||||||
return self.state.result(state)
|
return self.state.result(state)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue