Gomoku Code
Gomoku Code
Gomoku Code
for i in range(size):
for j in range(size):
if board[i][j] != ' ':
stone = board[i][j]
for direction in directions:
dx, dy = direction
count = 1
for k in range(1, 5):
x, y = i + k * dx, j + k * dy
if 0 <= x < size and 0 <= y < size and board[x]
[y] == stone:
count += 1
else:
break
if count == 5:
return stone
if len(check_available_moves(board)) == 0:
return "Draw"
return None
if len(available_moves) == 0:
return random.choice(check_available_moves(board))
else:
return random.choice(available_moves)
if choice == "1":
size = int(input("Enter the board size (9, 13, 15): "))
while size not in [9, 13, 15]:
size = int(input("Invalid size. Enter 9, 13, or 15: "))
board = create_board(size)
if mode == "pvp":
player_stone = "â"
computer_stone = "â"
else:
player_stone = "â"
computer_stone = "â"
print_board(board)
while True:
if mode == "pvp":
player_move = input(f"Player {player_stone}, enter
your move (e.g. '2 F'): ")
else:
player_move = input(f"Player {player_stone}, enter
your move (e.g. '2 F'): ")
if mode == "pvp":
computer_move = input(f"Player {computer_stone},
enter your move (e.g. '2 F'): ")
else:
computer_move = random_computer_player(board,
player_move)