Skip to content
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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

Tic Tac Toe example #2066

wants to merge 34 commits into from

Conversation

anuragts
Copy link
Contributor

Description

Tic tac toe example

Fixes # (issue)


Type of change

Please check the options that are relevant:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Model update (Addition or modification of models)
  • Other (please describe): Example

Checklist

  • Adherence to standards: Code complies with Agno’s style guidelines and best practices.
  • Formatting and validation: You have run ./scripts/format.sh and ./scripts/validate.sh to ensure code is formatted and linted.
  • Self-review completed: A thorough review has been performed by the contributor(s).
  • Documentation: Docstrings and comments have been added or updated for any complex logic.
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable).
  • Tested in a clean environment: Changes have been tested in a clean environment to confirm expected behavior.
  • Tests (optional): Tests have been added or updated to cover any new or changed functionality.

- 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
@anuragts anuragts requested a review from a team as a code owner February 10, 2025 11:41
@anuragts anuragts marked this pull request as draft February 10, 2025 11:41
- 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
@anuragts anuragts marked this pull request as ready for review February 10, 2025 16:13
@anuragts anuragts changed the title Tic tac toe example Tic Tac Toe example Feb 10, 2025
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the changes

Copy link
Contributor

@manthanguptaa manthanguptaa left a 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

@manthanguptaa
Copy link
Contributor

No options provided to select models

@anuragts
Copy link
Contributor Author

No options provided to select models

Sure this is good idea, thanks

Comment on lines 199 to 257
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

Copy link
Contributor

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?

Copy link
Contributor Author

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

@manthanguptaa
Copy link
Contributor

This has taken good shape now. Can you please remove the upload image functionality from the sidebar as its success rate is only 30%

@anuragts
Copy link
Contributor Author

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

@anuragts
Copy link
Contributor Author

@manthanguptaa Remove image upload

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants