Skip to content

Commit

Permalink
Add notebook for fieldwalk player help
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Oct 5, 2023
1 parent e0123c0 commit 57479aa
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
86 changes: 86 additions & 0 deletions resources/create_player_fieldwalk.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "SFNDJ1SSfNVU"
},
"outputs": [],
"source": [
"# Download and install package\n",
"!pip install git+https://github.com/jparisu/[email protected]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "wioHNbdZfce3"
},
"outputs": [],
"source": [
"# Imports\n",
"from IArena.arena.GenericGame import BroadcastGame\n",
"from IArena.games.FieldWalk import FieldWalkRules, FieldWalkMovement, FieldWalkPosition"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "mi-EZXqDflF0"
},
"outputs": [],
"source": [
"# Create your own player\n",
"class MyPlayer:\n",
"\n",
" def __init__(self, rules):\n",
" # Store the rules of the game\n",
" self.rules = rules\n",
"\n",
" def play(self, position: FieldWalkPosition) -> FieldWalkMovement:\n",
" # Code to play\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "087RDxY1liZ2"
},
"outputs": [],
"source": [
"# Make your player play in Hanoi\n",
"rules = FieldWalkRules()\n",
"my_champion = MyPlayer(rules)\n",
"\n",
"print(f\"Let's play!: {rules}\")\n",
"\n",
"# Broadcast to see the game iterations. If not use GenericGame\n",
"game = BroadcastGame(rules=rules, players=[my_champion])\n",
"result = game.play()\n",
"\n",
"your_score = result[0]\n",
"\n",
"print(f\"CONGRATULATIONS! You got it in {your_score} moves ☚ (<‿<)☚\")"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
3 changes: 1 addition & 2 deletions resources/create_player_hanoi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"source": [
"# Imports\n",
"from IArena.arena.GenericGame import BroadcastGame\n",
"from IArena.players.players import RandomPlayer\n",
"from IArena.games.Hanoi import HanoiRules, HanoiPosition, HanoiMovement"
]
},
Expand All @@ -41,7 +40,7 @@
" # Store the rules of the game\n",
" self.rules = rules\n",
"\n",
" def play(position):\n",
" def play(self, position: HanoiPosition) -> HanoiMovement:\n",
" # Code to play\n",
" pass"
]
Expand Down
7 changes: 7 additions & 0 deletions src/IArena/games/FieldWalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
Similar to BlindWalk but the player has access to the whole map from the beginning.
"""

FieldWalkSquare = BlindWalk.BlindWalkSquare
FieldWalkMovement = BlindWalk.BlindWalkMovement
MovementDirection = BlindWalk.MovementDirection
FieldWalkPosition = BlindWalk.BlindWalkPosition
FieldWalkMap = BlindWalk.BlindWalkMap
FieldWalkRules = BlindWalk.BlindWalkRules

class FieldWalkRules(BlindWalk.BlindWalkRules):

def __init__(
Expand Down

0 comments on commit 57479aa

Please sign in to comment.