diff options
author | Matt Strapp <strap012@umn.edu> | 2021-04-26 17:12:01 -0500 |
---|---|---|
committer | Matt Strapp <strap012@umn.edu> | 2021-04-26 17:12:01 -0500 |
commit | a093060b0e8a787e51212b5f2879dc839605da65 (patch) | |
tree | 7ec2d69219d41ae6447efc41ebaaac34c696984b /python/dotsandboxes | |
parent | Refactor jsut about everything (diff) | |
download | csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.tar csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.tar.gz csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.tar.bz2 csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.tar.lz csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.tar.xz csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.tar.zst csci4511w-a093060b0e8a787e51212b5f2879dc839605da65.zip |
Revert "Refactor jsut about everything"
This reverts commit e58a60ed18bde5db28ba96910df518a61b3999b2.
Diffstat (limited to '')
-rw-r--r-- | python/dotsandboxes/README.md | 134 | ||||
-rwxr-xr-x | python/dotsandboxes/dotsandboxesagent | 5 | ||||
-rw-r--r-- | python/dotsandboxes/dotsandboxesagent.py (renamed from dotsandboxes/agents/agent_random.py) | 0 | ||||
-rw-r--r-- | python/dotsandboxes/dotsandboxescompete.py (renamed from dotsandboxes/test/cli_compete.py) | 0 | ||||
-rw-r--r-- | python/dotsandboxes/dotsandboxesserver.py (renamed from dotsandboxes/server.py) | 2 | ||||
-rw-r--r-- | python/dotsandboxes/requirements.txt (renamed from requirements.txt) | 1 | ||||
-rw-r--r-- | python/dotsandboxes/static/dotsandboxes.css (renamed from dotsandboxes/web/dotsandboxes.css) | 0 | ||||
-rw-r--r-- | python/dotsandboxes/static/dotsandboxes.html (renamed from dotsandboxes/web/dotsandboxes.html) | 0 | ||||
-rw-r--r-- | python/dotsandboxes/static/dotsandboxes.js (renamed from dotsandboxes/web/dotsandboxes.js) | 0 |
9 files changed, 140 insertions, 2 deletions
diff --git a/python/dotsandboxes/README.md b/python/dotsandboxes/README.md new file mode 100644 index 0000000..e3f844c --- /dev/null +++ b/python/dotsandboxes/README.md @@ -0,0 +1,134 @@ +Dots and Boxes application +========================== + +Live demo: https://people.cs.kuleuven.be/wannes.meert/dotsandboxes/play + +![Screenshot of Dots and Boxes](https://people.cs.kuleuven.be/wannes.meert/dotsandboxes/screenshot.png?v=2) + +This setup is part of the course "Machine Learning: Project" (KU Leuven, +Faculty of engineering, Department of Computer Science, +[DTAI research group](https://dtai.cs.kuleuven.be)). + + +Installation +------------ + +The example agent is designed for Python 3.6 and requires the +[websockets](https://websockets.readthedocs.io) package. Dependencies can be +installed using pip: + + $ pip install -r requirements.txt + + +Start the game GUI +------------------ + +This program shows a web-based GUI to play the Dots and Boxes +game. This supports human-human, agent-human and agent-agent combinations. +It is a simple Javascript based application that runs entirely in the browser. +You can start it by opening the file `static/dotsandboxes.html` in a browser. +Or alternatively, you can start the app using the included simple server: + + $ ./dotsandboxesserver.py 8080 + +The game can then be played by directing your browser to http://127.0.0.1:8080. + + +Start the agent client +---------------------- + +This is the program that runs a game-playing agent. This application listens +to [websocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) +requests that communicate game information and sends back the next action it +wants to play. + +Starting the agent client is done using the following command: + + $ ./dotsandboxesagent <port> + +This starts a websocket on the given port that can receveive JSON messages. + +The JSON messages given below should be handled by your agent. +Take into account the maximal time allowed to reply. + +### Initiate the game + +Both players get a message that a new game has started: + + { + "type": "start", + "player": 1, + "timelimit", 0.5, + "grid": [5, 5], + "game": "123456" + } + +where `player` is the number assigned to this agent, `timelimit` is the +time in seconds in which you need to send your action back to the server, +and `grid` is the grid size in rows and columns. + +If you are player 1, reply with the first action you want to perform: + + { + "type": "action", + "location": [1, 1], + "orientation": "v" + } + +The field `location` is expressed as row and column (zero-based numbering) and +`orientation` is either "v" (vertical) or "h" (horizontal). + + +### Action in the game + +When an action is played, the message sent to both players is: + + { + "type": "action", + "game": "123456", + "player": 1, + "nextplayer": 2, + "score": [0, 0], + "location": [1, 1], + "orientation": "v" + } + + +If it is your turn you should answer with a message that states your next +move: + + { + "type": "action", + "location": [1, 1], + "orientation": "v" + } + + +### Game end + +When the game ends after an action, the message is slightly altered: + + { + "type": "end", + "game": "123456", + "player": 1, + "nextplayer": 0, + "score": [3, 1], + "location": [1, 1], + "orientation": "v", + "winner": 1 + } + +The `type` field becomes `end` and a new field `winner` is set to the player +that has won the game. + + +Contact information +------------------- + +- Wannes Meert, https://people.cs.kuleuven.be/wannes.meert +- Hendrik Blockeel, https://people.cs.kuleuven.be/hendrik.blockeel +- Arne De Brabandere, https://people.cs.kuleuven.be/arne.debrabandere +- Sebastijan Dumančić, https://people.cs.kuleuven.be/sebastijan.dumancic +- Pieter Robberechts, https://people.cs.kuleuven.be/pieter.robberechts + diff --git a/python/dotsandboxes/dotsandboxesagent b/python/dotsandboxes/dotsandboxesagent new file mode 100755 index 0000000..eecf719 --- /dev/null +++ b/python/dotsandboxes/dotsandboxesagent @@ -0,0 +1,5 @@ +#!/bin/bash +# It is not necessary to use a shell script for this. Dropping the .py +# extension and including the correct shebang is also correct. +python3 $(dirname "$0")/dotsandboxesagent.py $@ + diff --git a/dotsandboxes/agents/agent_random.py b/python/dotsandboxes/dotsandboxesagent.py index abf677b..abf677b 100644 --- a/dotsandboxes/agents/agent_random.py +++ b/python/dotsandboxes/dotsandboxesagent.py diff --git a/dotsandboxes/test/cli_compete.py b/python/dotsandboxes/dotsandboxescompete.py index ee2aee8..ee2aee8 100644 --- a/dotsandboxes/test/cli_compete.py +++ b/python/dotsandboxes/dotsandboxescompete.py diff --git a/dotsandboxes/server.py b/python/dotsandboxes/dotsandboxesserver.py index 914ab45..1b66372 100644 --- a/dotsandboxes/server.py +++ b/python/dotsandboxes/dotsandboxesserver.py @@ -23,7 +23,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): if self.path == "/": self.send_response(302) - self.send_header("Location", "web/dotsandboxes.html") + self.send_header("Location", "static/dotsandboxes.html") self.end_headers() return super().do_GET() diff --git a/requirements.txt b/python/dotsandboxes/requirements.txt index af05743..14774b4 100644 --- a/requirements.txt +++ b/python/dotsandboxes/requirements.txt @@ -1,2 +1 @@ websockets -numpy
\ No newline at end of file diff --git a/dotsandboxes/web/dotsandboxes.css b/python/dotsandboxes/static/dotsandboxes.css index 71b1d3b..71b1d3b 100644 --- a/dotsandboxes/web/dotsandboxes.css +++ b/python/dotsandboxes/static/dotsandboxes.css diff --git a/dotsandboxes/web/dotsandboxes.html b/python/dotsandboxes/static/dotsandboxes.html index 4e97508..4e97508 100644 --- a/dotsandboxes/web/dotsandboxes.html +++ b/python/dotsandboxes/static/dotsandboxes.html diff --git a/dotsandboxes/web/dotsandboxes.js b/python/dotsandboxes/static/dotsandboxes.js index 11e9447..11e9447 100644 --- a/dotsandboxes/web/dotsandboxes.js +++ b/python/dotsandboxes/static/dotsandboxes.js |