Compare commits
4 Commits
main
...
agent/snea
| Author | SHA1 | Date |
|---|---|---|
|
|
c0ebfaa2bd | |
|
|
52ad1de7cd | |
|
|
6ecb1101c8 | |
|
|
8b42819184 |
|
|
@ -10,11 +10,9 @@
|
||||||
from .agent import Agent
|
from .agent import Agent
|
||||||
from .chaos import AgentOfChaos
|
from .chaos import AgentOfChaos
|
||||||
from .mute import MuteAgent
|
from .mute import MuteAgent
|
||||||
from .remote import RemoteAgent
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Agent",
|
"Agent",
|
||||||
"AgentOfChaos",
|
"AgentOfChaos",
|
||||||
"MuteAgent",
|
"MuteAgent",
|
||||||
"RemoteAgent",
|
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -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) }
|
||||||
|
|
@ -20,6 +20,7 @@ RUN pip install --no-cache-dir --no-index --find-links=/wheels \
|
||||||
|
|
||||||
# Install PyServer code
|
# Install PyServer code
|
||||||
COPY pyserver/ pyserver/
|
COPY pyserver/ pyserver/
|
||||||
|
COPY agents/ agents/
|
||||||
COPY server.py .
|
COPY server.py .
|
||||||
|
|
||||||
CMD ["python", "server.py"]
|
CMD ["python", "server.py"]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import agents
|
import agents.sneaky
|
||||||
|
|
||||||
from pyserver import PyServer
|
from pyserver import PyServer
|
||||||
|
|
||||||
|
|
@ -15,7 +15,7 @@ def main() -> int:
|
||||||
:return: Exit code
|
:return: Exit code
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
player = PyServer(agents.AgentOfChaos())
|
player = PyServer(agents.sneaky.SneakyAgent())
|
||||||
|
|
||||||
# Start listening for games
|
# Start listening for games
|
||||||
player.start(
|
player.start(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue