Example #1
0
def put():
    data = request.get_json()
    b1 = data["board"]
    x = int(data["x"])
    y = int(data["y"])
    adv = data["adv"]
    if adv:
        W = deepcopy(data["W"])
        w = deepcopy(data["w"])
    b2 = []
    for i in range(8):
        b2.append(list(b1[i * 8:(i + 1) * 8]))
    mode = "maxmin" if data["mode"] == 'settai' else "minmax"
    if data["difficulty"] == 0:
        mode = "random"
    depth = int(data["difficulty"])
    p = get_player_instance(mode, "B")
    q = get_player_instance(mode, "W")
    b = Board(b2)
    # PLAYER'S TURN
    if x >= 0:
        if validate(b.board_data, "B", [x, y]):
            do_move(b.board_data, "B", [x, y])
    plisult = deepcopy(b.board_data)
    if adv and depth > 0:
        nm = q.next_move(b.board_data, "W", depth, W, w)
    elif depth > 0:
        nm = q.next_move(b.board_data, "W", depth)
    else:
        nm = q.next_move(b.board_data, "W")
    if validate(b.board_data, "W", nm):
        do_move(b.board_data, "W", nm)
    qlisult = b.board_data
    return jsonify({"player": plisult, "com": qlisult, "pos": nm})
Example #2
0
 def get_valid_pos(self):
     moves = []
     for y in range(8):
         for x in range(8):
             if game.validate(self._board, self._color, [x, y]):
                 moves.append([x, y])
     return moves
 def valid_pos(self, player):
     moves = []
     for y in range(8):
         for x in range(8):
             if validate(self.board_data, player.color, [x, y]):
                 moves.append([x, y])
     return moves
Example #4
0
 def next_move(self, board, color, depth=2, W=None, w=None):
     if game.validate(board, color, 'pass'):
         return "pass"
     mov, val = self.max_val(board,
                             -self.inf,
                             self.inf,
                             depth,
                             color,
                             W=W,
                             w=w)
     return mov
Example #5
0
 def successors(self, state, color):
     suclist = []
     movs = []
     for y in range(8):
         for x in range(8):
             if game.validate(state, color, [x, y]):
                 movs.append([x, y])
     for mov in movs:
         nb = deepcopy(state)
         game.do_move(nb, color, mov)
         suclist.append([mov, nb])
     return suclist
Example #6
0
 def end_state(self, state):
     return game.validate(state, "B", "pass") and game.validate(
         state, "W", "pass")
 def is_game_over(self):
     return validate(self.board_data, "B", 'pass') and validate(
         self.board_data, "W", 'pass')