def move(): game_state = bottle.request.json new_board = update_board(game_state) turn = game_state['turn'] # for testing direction = calculate_move(new_board, game_state) return move_response(direction)
def play(): while not variables.finish: if variables.curPlayer == 1: variables.curChess = "*" print("\033[1;37;40m * - Enter the coords of the chess (e.g. A0): \033[0m") else: variables.curChess = "o" print("\033[1;30;42m o - Enter the coords of the chess (e.g. A0): \033[0m") user_input = input() ch = user_input[0] x = ord(ch.upper()) - 65 y = int(user_input[1]) if exist(x, y) and len(user_input) == 2: flag = update_board(x, y) if flag == 0: print("\033[31m****** The place has been taken! Please try again! \033[0m") continue f = check_win(x, y) if f == 1: win() break swap_player() show_board() else: print("\033[31m*** Invalid coords! Please try again! ***\033[0m")
def game(message): if not (message.get('piece') and message.get('room') and message.get('color')): # send message that tells invalid return room_name_key = f'room:{message["room"]}' # その部屋のボードを取りに行く board = json.loads(cache.hget(room_name_key, 'board').decode()) current_color = cache.hget(room_name_key, 'next').decode() if current_color != message["color"]: print("変です") # print(dict(board)) new_next = "white" if current_color == "black" else "black" # update_board()する new_board = board_manager.update_board(board, message.get('piece'), message["color"]) # print(new_board) cache.hset(room_name_key, "next", new_next) cache.hset(room_name_key, "board", json.dumps(new_board)) generated_board = board_manager.generate_board_to_send(new_board) # can_place() (ボードを渡すと、「両方の色」が置ける場所を配列で返してくれるくん)でどこに置けるかを知る # can_place(board) == {"white":[...], "black": [...]} # どっちも空配列だったらゲーム終了のお知らせ # 自分の置ける場所がなければパスです # この時点でDBを更新 # update_board_with_can_place()して、boardオブジェクトにcan_placeを挿入 # 送り返して終了 emit('game', { "board": generated_board, "turn": current_color }, room=room_name_key)
def move(): directions = ['up', 'down', 'left', 'right'] game_state = bottle.request.json new_board = update_board(game_state) direction = calculate_move(new_board, game_state) return move_response(direction)
def move(): start_time = time.time() game_state = bottle.request.json new_board = update_board(game_state) turn = game_state['turn'] # for testing print("Turn:",turn) direction = calculate_move(new_board, game_state) total_time = time.time() - start_time print('TOTAL TIME FOR MOVE: ' + str(total_time)) return move_response(direction)
def _human_turn(self, board, player: int): player_move = int(input(f"({self.it}) YOUR MOVE (0 to 8): ")) # move range check if player_move < 0 or player_move > 8: while player_move < 0 or player_move > 8: print("Invalid move! Not in range [0, 8].") player_move = int(input(f"({self.it}) YOUR MOVE (0 to 8): ")) new_board = update_board(board, player, player_move) # invalid move check if new_board is None: while new_board is None: print("Invalid move!") player_move = int(input("YOUR MOVE (0 to 8): ")) new_board = update_board(board, player, player_move) return new_board
def mp_max_search(inputs): """Special case of the first move for multiprocessing.""" board = inputs[0] move = inputs[1] token = inputs[2] opp_token = inputs[3] temp_board = update_board(board, move, token) winner = evaluate_board(temp_board) if winner != TOKENS.BLANK: value = get_value(winner, token, opp_token) else: _, value = mini_search(temp_board, token, opp_token) return move, value
def mini_search(board, token, opp_token): """Search for the best move your opponent can make.""" best_value = None best_move = None for move in possible_moves(board): temp_board = update_board(board, move, opp_token) winner = evaluate_board(temp_board) if winner != TOKENS.BLANK: value = get_value(winner, token, opp_token) else: _, value = max_search(temp_board, token, opp_token) if best_value is None or value < best_value: best_value = value best_move = move return best_move, best_value
def move(): start_time = time.time() game_state = bottle.request.json new_board = update_board(game_state) my_head = (game_state['you']['body'][0]['x'], game_state['you']['body'][0]['y']) my_tail = (game_state['you']['body'][-1]['x'], game_state['you']['body'][-1]['y']) my_health = game_state['you']['health'] my_size = len(game_state['you']['body']) direction = calculate_move(new_board, my_head, my_tail, my_health, my_size) total_time = time.time() - start_time print('TOTAL TIME FOR MOVE: ' + str(total_time)) return move_response(direction)
def _bot_turn(self, board, player: int): bot = Bot(player) start_time = time() if self.bot_type == "random": bot_move = bot.move_random(board) else: bot_move = bot.move_minimax(board, player)[1] end_time = round(time() - start_time, 2) print(f"({self.it}) BOT MOVE ({end_time}s): {bot_move}") new_board = update_board(board, bot.player, bot_move) return new_board
def move(): game_state = bottle.request.json new_board = update_board(game_state) direction = "" # Change the number of snake_num to change the snake # 1 = random snake # 2 = food snake # 3 = wall snake # 4 = smart snake snake_num = 4 if snake_num == 1: direction = random_move() if snake_num == 2: direction = food_move(game_state, new_board) if snake_num == 3: direction = wall_move(game_state, new_board) if snake_num == 4: direction = smart_move(game_state, new_board) return move_response(direction)
# Make a board structure to fill in the data with. empty_board = [[0 for _ in range(9)] for _ in range(9)] # Fill Board with puzzle data puzzle_board = fill_board(puzzle) solution_board = fill_board(solution) rowsValid(solution_board) cols_vald(solution_board) pyxel.init(156, 183, caption="Sudoku Game") # change board selected_value = 1 cell_selected = (0, 0) update_board(puzzle_board, 4, 4, 8) pyxel.cls(3) pyxel.text(1, 1, "8", 0) is_valid = True pyxel.load("my_resource.pyxres", True, True) image = pyxel.image(0) # start the game # pyxel.mouse(True) pyxel.run(update, draw) print("That was fun, why don't we play again?")
"""Sudoku Game""" from App_class import App import new_board import board puzzle, solution = new_board.format_puzzle( new_board.read_line_from_puzzlefile("sudoku.csv")) our_app = App(new_board.fill_board(puzzle), new_board.fill_board(solution), is_valid=True, cell_selected=(0, 0), game_won=False, selected_value=1) board.update_board(our_app.puzzle_board, 4, 4, 8) our_app.run() print( "If you reached this point, you've come too far. Think about your choices in life." )
def play(self, pos, board): """Make the move at pos.""" board = update_board(board, pos, self.token) return board