Source code for haive.games.single_player.flow_free.engines
"""Prompt generation and engine configuration for Flow Free.This module defines prompt templates and LLM configurations for move generation andposition analysis in the Flow Free game."""fromhaive.core.engine.aug_llmimportAugLLMConfigfromhaive.core.models.llm.baseimportAzureLLMConfigfromlangchain_core.promptsimportChatPromptTemplatefromhaive.games.single_player.flow_free.modelsimportFlowFreeAnalysis,FlowFreeMove
[docs]defgenerate_move_prompt()->ChatPromptTemplate:"""Generate a prompt template for Flow Free move generation. Returns: A prompt template for move generation. """returnChatPromptTemplate.from_messages([("system","""You are playing the Flow Free puzzle game. In this game, you need to connect pairs of colored dots with pipes. The rules are:1. Connect each pair of same-colored dots with a continuous pipe2. Pipes cannot cross or overlap3. Every cell on the grid must be filled with a pipe4. A pipe can only make 90-degree turnsYour job is to decide the next move in the game based on the current board state.""",),("human","""Current Board:{board_display}Game Status:- Moves so far: {move_count}- Completed Flows: {completed_flows_count}/{total_flows}- Board Fill: {board_fill_percentage:.1f}%{flow_status}The valid moves are:{valid_moves}You need to select the next move. Consider which flow to extend and where to place the next pipe segment.Think carefully about avoiding blocking other flows and ensuring all cells can eventually be filled.Return your move as a FlowFreeMove object with the flow_id and position (row, col) of where to place the next pipe segment.""",),])
[docs]defgenerate_analysis_prompt()->ChatPromptTemplate:"""Generate a prompt template for Flow Free position analysis. Returns: A prompt template for position analysis. """returnChatPromptTemplate.from_messages([("system","""You are an expert Flow Free puzzle analyzer. In this game, the goal is to connect pairs of colored dots with pipes while following these rules:1. Connect each pair of same-colored dots with a continuous pipe2. Pipes cannot cross or overlap3. Every cell on the grid must be filled with a pipe4. A pipe can only make 90-degree turnsYour job is to analyze the current board state, identify critical flows, blocked paths, and recommend the best next move.""",),("human","""Current Board:{board_display}Game Status:- Moves so far: {move_count}- Completed Flows: {completed_flows_count}/{total_flows}- Board Fill: {board_fill_percentage:.1f}%{flow_status}{hint_request}Analyze this position. Consider:1. Which flows are most constrained and should be prioritized?2. Are there any flows at risk of being blocked?3. Which flow should be extended next and in which direction?4. What is the optimal strategy for completing the puzzle?Provide a detailed analysis and recommend the best next move.""",),])