-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tic Tac Toe example #2066
base: main
Are you sure you want to change the base?
Tic Tac Toe example #2066
Conversation
- Add comprehensive TicTacToeBoard utility class in utils.py - Enhance agents.py with full game logic and AI agent interactions - Implement game flow with move validation, winner checking, and draw detection - Add support for running the game directly or via import - Include detailed agent roles and game rules
- Relocated move history display to improve game flow - Ensure move history is always visible during active game - Minor refactoring of main game logic placement
- Extend ModelConfig to support Ollama as a model provider - Add Ollama import from agno.models.ollama - Implement provider-based model selection with Ollama option - Add error handling for invalid provider configurations
- Update module docstring with more detailed usage examples and game overview - Extend get_tic_tac_toe() function to support flexible model selection - Add configurable model providers for X and O players - Improve function documentation with clear parameter descriptions - Implement dynamic model and agent configuration parsing
- Add Google Gemini model support to ModelConfig - Introduce DEFAULT_MODELS dictionary for simplified model assignment - Simplify get_tic_tac_toe() function with more flexible model configuration - Update app.py to use new model configuration approach - Remove redundant agent configuration logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use the names Tic Agent
and Tac Agent
. Use instead Player 1 and Player 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had like a better way to showcase the history instead of on the left hand side in the sidebar. Each move should be showed on the board and on the main screen
No options provided to select models |
Sure this is good idea, thanks |
def play_tic_tac_toe(debug_mode: bool = True) -> None: | ||
""" | ||
Start and manage a game of Tic Tac Toe between two AI agents. | ||
|
||
Args: | ||
debug_mode (bool): Whether to show debug information during the game | ||
""" | ||
# Initialize the game | ||
master_agent = get_tic_tac_toe(debug_mode=debug_mode) | ||
game_board = TicTacToeBoard() | ||
|
||
print("Starting a new game of Tic Tac Toe!") | ||
print(game_board.get_board_state()) | ||
|
||
# Game loop | ||
while True: | ||
# Get current player | ||
current_player = "X" if game_board.current_player == "X" else "O" | ||
agent = master_agent.team[0] if current_player == "X" else master_agent.team[1] | ||
|
||
# Get agent's move | ||
print(f"\n{current_player}'s turn ({agent.name}):") | ||
valid_moves = game_board.get_valid_moves() | ||
|
||
response = agent.run( | ||
f"""Current board state:\n{game_board.get_board_state()}\n | ||
Available valid moves (row, col): {valid_moves}\n | ||
Choose your next move from the valid moves list above. | ||
Respond with ONLY two numbers for row and column, e.g. "1 2".""", | ||
stream=False, | ||
) | ||
|
||
# Parse move from response content | ||
try: | ||
import re | ||
|
||
numbers = re.findall(r"\d+", response.content if response else "") | ||
row, col = map(int, numbers[:2]) | ||
success, message = game_board.make_move(row, col) | ||
print(message) | ||
|
||
if not success: | ||
print("Invalid move! Try again.") | ||
continue | ||
|
||
except (ValueError, IndexError): | ||
print("Invalid move format! Try again.") | ||
continue | ||
|
||
# Check for game end | ||
winner = game_board.check_winner() | ||
if winner: | ||
print(f"\nGame Over! {winner} wins!") | ||
break | ||
|
||
if game_board.is_board_full(): | ||
print("\nGame Over! It's a draw!") | ||
break | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be moved to utils I feel. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, moved
This has taken good shape now. Can you please remove the upload image functionality from the sidebar as its success rate is only 30% |
Sure |
@manthanguptaa Remove image upload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a README via cursor. Let me know if you are happy
Description
Tic tac toe example
Fixes # (issue)
Type of change
Please check the options that are relevant:
Checklist
./scripts/format.sh
and./scripts/validate.sh
to ensure code is formatted and linted.