SHARE
TWEET

Untitled

a guest Dec 16th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Random simulation
  2. def roll_out(self):
  3.     self.visits += 1
  4.     settings.path.append(int(self.index))
  5.     board = copy.deepcopy(self.state)             # starting state of board
  6.     player = Player(self.state, self.color)
  7.     opponent = Player(board, self.opp)
  8.     if checkmate(board, self.color):              # is the starting state already checkmate?
  9.         value, self.win = 20, True
  10.         settings.value[self.color] = value
  11.         return
  12.     if opponent.draw:                             # is the starting state already a draw?
  13.         value, self.draw = 5, True
  14.         settings.value[self.color] = value
  15.         return
  16.     for i in range(1000):
  17.         self.random_move(opponent, board)         # moves a random piece
  18.         player.set_moves(board)                   # update our legal moves
  19.         if player.draw:
  20.             value = 5
  21.             settings.value[self.color] = value
  22.             return
  23.         if opponent.won:
  24.             value = 0
  25.             settings.value[self.color] = value
  26.             return
  27.         if len(opponent.pieces) == 1 and len(player.pieces) == 1:
  28.             value = 5
  29.             settings.value[self.color] = value
  30.             return
  31.         self.random_move(player, board)           # moves a random piece
  32.         opponent.set_moves(board)                 # update opponents legal moves
  33.         if opponent.draw:
  34.             value = 5
  35.             settings.value[self.color] = value
  36.             return
  37.         if player.won:
  38.             value = 20
  39.             settings.value[self.color] = value
  40.             return
  41.         if len(player.pieces) == 1 and len(opponent.pieces) == 1:
  42.             value = 5
  43.             settings.value[self.color] = value
  44.             return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top