Skip to content
TheChatArchiveThe Chat Archive
Mistralmistral-medium-2505· Mistral AIHugging Face LMArena Human Preference 140K

Make it turn based. On player turn show context menu with options to either move or…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Hunyuanhunyuan-turbos-20250416’s answer.
  1. User

    Make it turn based. On player turn show context menu with options to either move or attack. Each action should take some amount of time, eg. attack cost is 5, moving 1 place costs 3, moving 2 places costs 6 etc. Use a* for movement. Make some cells blocks that cannot be moved through

  2. Mistral Assistant

    Here's a turn-based isometric game prototype with A* pathfinding, action costs, and blocking terrain:

    import pygame
    import sys
    import math
    import random
    import heapq
    from enum import Enum
    
    # --- CONFIG ---
    SCREEN_W, SCREEN_H = 800, 600
    TILE_W, TILE_H = 64, 32
    MAP_W, MAP_H = 10, 10
    GRID = [[0 for _ in range(MAP_W)] for _ in range(MAP_H)]  # 0=walkable, 1=blocked
    
    # Action costs
    MOVE_COST = 3
    ATTACK_COST = 5
    
    # --- HELPERS ---
    def world_to_iso(x, y):
        """Convert map coords to screen iso coords."""
        iso_x = (x - y) * TILE_W//2 + SCREEN_W//2
        iso_y = (x + y) * TILE_H//2 + SCREEN_H//4
        return iso_x, iso_y
    
    def draw_tile(surf, gx, gy):
        """Draw a single diamond tile at grid pos (gx,gy)."""
        cx, cy = world_to_iso(gx, gy)
        pts = [
            (cx, cy + TILE_H//2),
            (cx + TILE_W//2, cy),
            (cx + TILE_W, cy + TILE_H//2),
            (cx + TILE_W//2, cy + TILE_H)
        ]
        color = (50, 50, 50) if GRID[gy][gx] == 0 else (100, 100, 100)
        pygame.draw.polygon(surf, color, pts)
        pygame.draw.polygon(surf, (0, 0, 0), pts, 1)
    
    def heuristic(a, b):
        """Manhattan distance for A* heuristic."""
        return abs(a[0] - b[0]) + abs(a[1] - b[1])
    
    def a_star(start, goal):
        """A* pathfinding algorithm."""
        if GRID[goal[1]][goal[0]] == 1:  # Check if goal is blocked
            return None
    
        open_set = []
        heapq.heappush(open_set, (0, start))
        came_from = {}
        g_score = {start: 0}
        f_score = {start: heuristic(start, goal)}
    
        while open_set:
            current = heapq.heappop(open_set)[1]
    
            if current == goal:
                path = []
                while current in came_from:
                    path.append(current)
                    current = came_from[current]
                path.reverse()
                return path
    
            for dx, dy in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
                neighbor = (current[0] + dx, current[1] + dy)
    
                if (0 <= neighbor[0] < MAP_W and 0 <= neighbor[1] < MAP_H and
                    GRID[neighbor[1]][neighbor[0]] == 0):
    
                    tentative_g_score = g_score[current] + MOVE_COST
    
                    if neighbor not in g_score or tentative_g_score < g_score[neighbor]:
                        came_from[neighbor] = current
                        g_score[neighbor] = tentative_g_score
                        f_score[neighbor] = tentative_g_score + heuristic(neighbor, goal)
                        heapq.heappush(open_set, (f_score[neighbor], neighbor))
    
        return None  # No path found
    
    # --- ENTITIES ---
    class Entity:
        def __init__(self, x, y, color, is_player=False):
            self.x = x
            self.y = y
            self.color = color
            self.is_player = is_player
            self.action_points = 10 if is_player else 5
    
        def iso_pos(self):
            return world_to_iso(self.x, self.y)
    
        def draw(self, surf):
            cx, cy = self.iso_pos()
            pygame.draw.circle(surf, self.color, (int(cx + TILE_W//2), int(cy + TILE_H//2)), 10)
    
            # Draw action points
            if self.is_player:
                font = pygame.font.SysFont(None, 24)
                text = font.render(f"AP: {self.action_points}", True, (255, 255, 255))
                surf.blit(text, (cx + TILE_W//2 - 20, cy + TILE_H//2 - 30))
    
    # --- GAME STATE ---
    class GameState(Enum):
        PLAYER_TURN = 1
        ENEMY_TURN = 2
        SHOW_MENU = 3
        SHOW_MOVE_RANGE = 4
        SHOW_ATTACK_RANGE = 5
    
    # --- INIT ---
    pygame.init()
    screen = pygame.display.set_mode((SCREEN_W, SCREEN_H))
    clock = pygame.time.Clock()
    font = pygame.font.SysFont(None, 24)
    
    # Generate some blocked tiles
    for _ in range(15):
        x, y = random.randint(0, MAP_W-1), random.randint(0, MAP_H-1)
        GRID[y][x] = 1
    
    player = Entity(2, 2, (50, 150, 255), is_player=True)
    monsters = [Entity(random.randint(0, MAP_W-1), random.randint(0, MAP_H-1), (200, 50, 50))
                for _ in range(3)]
    
    game_state = GameState.PLAYER_TURN
    selected_action = None
    selected_target = None
    path = []
    
    # --- MAIN LOOP ---
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
    
            if game_state == GameState.SHOW_MENU:
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_m:
                        selected_action = "move"
                        game_state = GameState.SHOW_MOVE_RANGE
                    elif event.key == pygame.K_a:
                        selected_action = "attack"
                        game_state = GameState.SHOW_ATTACK_RANGE
                    elif event.key == pygame.K_e:
                        game_state = GameState.ENEMY_TURN
    
            elif game_state in [GameState.SHOW_MOVE_RANGE, GameState.SHOW_ATTACK_RANGE]:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    mouse_x, mouse_y = pygame.mouse.get_pos()
    
                    # Convert screen coords to grid coords
                    grid_x = (mouse_x / (TILE_W//2) + mouse_y / (TILE_H//2)) / 2
                    grid_y = (mouse_y / (TILE_H//2) - (mouse_x / (TILE_W//2))) / 2
    
                    grid_x, grid_y = int(round(grid_x)), int(round(grid_y))
    
                    if 0 <= grid_x < MAP_W and 0 <= grid_y < MAP_H:
                        if selected_action == "move":
                            path = a_star((player.x, player.y), (grid_x, grid_y))
                            if path and len(path) - 1 <= player.action_points // MOVE_COST:
                                selected_target = (grid_x, grid_y)
                                game_state = GameState.PLAYER_TURN
                        elif selected_action == "attack":
                            # Check if target is in attack range
                            if (abs(grid_x - player.x) + abs(grid_y - player.y)) <= 1:
                                for monster in monsters:
                                    if monster.x == grid_x and monster.y == grid_y:
                                        selected_target = monster
                                        game_state = GameState.PLAYER_TURN
                                        break
    
        # --- GAME LOGIC ---
        if game_state == GameState.PLAYER_TURN:
            if selected_action == "move" and selected_target:
                # Move player along path
                if path:
                    next_pos = path[1]  # First step in path
                    cost = MOVE_COST * len(path)
                    if player.action_points >= cost:
                        player.x, player.y = next_pos
                        player.action_points -= cost
                        selected_action = None
                        selected_target = None
                        path = []
                        game_state = GameState.ENEMY_TURN
                    else:
                        # Not enough AP, cancel move
                        selected_action = None
                        selected_target = None
                        path = []
                        game_state = GameState.SHOW_MENU
    
            elif selected_action == "attack" and selected_target:
                # Attack monster
                if player.action_points >= ATTACK_COST:
                    player.action_points -= ATTACK_COST
                    monsters.remove(selected_target)
                    selected_action = None
                    selected_target = None
                    game_state = GameState.ENEMY_TURN
                else:
                    # Not enough AP, cancel attack
                    selected_action = None
                    selected_target = None
                    game_state = GameState.SHOW_MENU
    
        elif game_state == GameState.ENEMY_TURN:
            # Simple enemy AI: move toward player if possible
            for monster in monsters:
                if monster.action_points > 0:
                    # Find path to player
                    path = a_star((monster.x, monster.y), (player.x, player.y))
                    if path and len(path) > 1:
                        next_pos = path[1]
                        if monster.action_points >= MOVE_COST:
                            monster.x, monster.y = next_pos
                            monster.action_points -= MOVE_COST
    
            # End enemy turn
            game_state = GameState.PLAYER_TURN
            player.action_points = 10  # Reset player AP
            for monster in monsters:
                monster.action_points = 5  # Reset monster AP
    
        # --- DRAWING ---
        screen.fill((30, 30, 30))
    
        # Draw tiles
        for gy in range(MAP_H):
            for gx in range(MAP_W):
                draw_tile(screen, gx, gy)
    
        # Draw path if showing move range
        if game_state == GameState.SHOW_MOVE_RANGE and path:
            for pos in path[1:]:  # Skip first position (player's current position)
                cx, cy = world_to_iso(pos[0], pos[1])
                pygame.draw.circle(screen, (0, 200, 0), (int(cx + TILE_W//2), int(cy + TILE_H//2)), 8)
    
        # Draw attack range
        if game_state == GameState.SHOW_ATTACK_RANGE:
            for dx in [-1, 0, 1]:
                for dy in [-1, 0, 1]:
                    if dx == 0 and dy == 0:
                        continue
                    nx, ny = player.x + dx, player.y + dy
                    if 0 <= nx < MAP_W and 0 <= ny < MAP_H:
                        cx, cy = world_to_iso(nx, ny)
                        pygame.draw.circle(screen, (200, 0, 0), (int(cx + TILE_W//2), int(cy + TILE_H//2)), 8)
    
        # Draw entities
        all_sprites = monsters + [player]
        for ent in sorted(all_sprites, key=lambda e: e.x + e.y):
            ent.draw(screen)
    
        # Draw menu if needed
        if game_state == GameState.SHOW_MENU:
            menu_text = [
                "M - Move",
                "A - Attack",
                "E - End Turn"
            ]
            for i, text in enumerate(menu_text):
                text_surf = font.render(text, True, (255, 255, 255))
                screen.blit(text_surf, (50, 50 + i * 30))
    
        pygame.display.flip()
        clock.tick(60)
    
    pygame.quit()
    sys.exit()
    

    Key Features:

    1. Turn-Based System:

      • Player and enemies take turns
      • Action points system (player gets 10 AP, monsters get 5 AP per turn)
    2. A Pathfinding*:

      • Calculates optimal paths around blocked tiles
      • Movement cost is 3 AP per tile
    3. Action System:

      • Move (3 AP per tile)
      • Attack (5 AP)
      • End turn option
    4. Blocked Terrain:

      • Randomly generated blocked tiles (gray)
      • Pathfinding avoids these tiles
    5. Visual Feedback:

      • Shows movement range when selecting move
      • Shows attack range when selecting attack
      • Displays remaining action points
    6. Enemy AI:

      • Simple AI that moves toward player
      • Uses same pathfinding as player

    Controls:

    • When it's your turn, press:
      • M: Show movement range (click to move)
      • A: Show attack range (click to attack)
      • E: End turn

    The game alternates between player and enemy turns, with each side getting action points to spend on movement or attacks. The A* pathfinding ensures movement is intelligent and avoids blocked tiles.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.