From 8b428191849952f6c4247238df92293d1bfd44ff Mon Sep 17 00:00:00 2001 From: schipeltaper Date: Wed, 1 Jul 2026 17:51:04 +0200 Subject: [PATCH] implemented a sneaky agent --- agents/sneaky.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 agents/sneaky.py diff --git a/agents/sneaky.py b/agents/sneaky.py new file mode 100644 index 0000000..fbf77b6 --- /dev/null +++ b/agents/sneaky.py @@ -0,0 +1,89 @@ +""" + The sneaky agent is built to trick the naive line counter agent. + I believe if the sneaky agent starts, they will win against the line counter agent. + I have not tested this yet, as the naive line counter agent wasn't in the branch I checked out and I'm lazy, + so time will tell... +""" + +from __future__ import annotations + +import random + +from .agent import Agent, Payload + +class SneakyAgent(Agent): + """ + It tries to get both opposite corners (1 and 9) and then get another corner that would give it two routes to win + """ + + def __init__(self) -> None: + """ + Create a new instance of the sneaky agent. + """ + + super().__init__( + # Give your bot a name to display in leaderboards + name="Sneaky agent", + + # Your name, to give you credit + author="Sam", + + # Update the version to indicate the agent behaves differently. + # This will later allow you to compare different versions of your + # agent against one another. + version="1.0.0", + + # Add extra custom information about the agent to this dictionary. + profile={}, + ) + + # Indicate that you're willing to play tic-tac-toe + # Remove this if you don't want your bot to participate there. + self.add_tic_tac_toe(on_move=self.play_tic_tac_toe, profile={}) + + @staticmethod + def play_tic_tac_toe(payload : Payload) -> Payload: + """ + I've placed move comments to indicate which move that would be in the ideal game against the line counter. + This assumes this agent starts and so move 1 is {"move": 1}, etc... + + If none of the options are valid, we return a random move + """ + + # Try printing the payload to see what it looks like! + print(payload) + + # Current State + cs = dict(payload) + + # Move 1 + if cs["1"] == "": + return { "move": 1} + + # Move 2 + if cs["9"] == "": + return { "move": 9} + + # Move 4 + if cs["2"] == "" and cs["1"] == cs["your_token"] and cs["3"] == cs["your_token"]: + return { "move": 2} + + if cs["6"] == "" and cs["3"] == cs["your_token"] and cs["9"] == cs["your_token"]: + return { "move": 6} + + if cs["8"] == "" and cs["7"] == cs["your_token"] and cs["9"] == cs["your_token"]: + return { "move": 8} + + if cs["4"] == "" and cs["1"] == cs["your_token"] and cs["7"] == cs["your_token"]: + return { "move": 4} + + # Move 3 + if cs["2"] == "" and cs["6"] == "" and cs["3"] == "": + return { "move": 3} + + if cs["4"] == "" and cs["8"] == "" and cs["7"] == "": + return { "move": 7} + + # If the sneaky strategy doesn't work + options = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, ] + return { "move": random.choice(options) } \ No newline at end of file