aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2021-04-26 10:53:43 -0500
committerMatt Strapp <strap012@umn.edu>2021-04-26 15:03:24 -0500
commit7535ef51e84067e27f1a4c53f8889047f3a9a098 (patch)
treee5f1f9da55fb2ba2b2c482a608a328f68ddbd012 /python
parentTest commit (diff)
downloadcsci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.tar
csci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.tar.gz
csci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.tar.bz2
csci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.tar.lz
csci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.tar.xz
csci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.tar.zst
csci4511w-7535ef51e84067e27f1a4c53f8889047f3a9a098.zip
change base???
Diffstat (limited to 'python')
-rw-r--r--python/MCTS.py9
-rw-r--r--python/agent.py55
-rw-r--r--python/dotsandboxes/dotsandboxesagent.py5
-rw-r--r--python/dotsandboxes/static/dotsandboxes.html12
-rwxr-xr-xpython/start.sh7
5 files changed, 88 insertions, 0 deletions
diff --git a/python/MCTS.py b/python/MCTS.py
index 6c71ba9..ec6e6c1 100644
--- a/python/MCTS.py
+++ b/python/MCTS.py
@@ -1,6 +1,10 @@
import math
from copy import deepcopy
+<<<<<<< HEAD
from time import perf_counter
+=======
+from time import clock
+>>>>>>> f6e623d... change base???
from random import choice
from GameState import GameState
@@ -135,8 +139,13 @@ class MCTSGameController(GameController):
self.root_node = MCTSNode(state)
iterations = 0
+<<<<<<< HEAD
start_time = perf_counter()
while perf_counter() < start_time + time_allowed:
+=======
+ start_time = clock()
+ while clock() < start_time + time_allowed:
+>>>>>>> f6e623d... change base???
node = self.select()
if node.pending_moves != set():
diff --git a/python/agent.py b/python/agent.py
new file mode 100644
index 0000000..49bc1cc
--- /dev/null
+++ b/python/agent.py
@@ -0,0 +1,55 @@
+import dotsandboxes.dotsandboxesagent as dba
+
+import sys
+import argparse
+import logging
+from GameState import GameState, DotsAndBoxesState
+from MCTS import MCTSNode, MCTSGameController
+
+
+logger = logging.getLogger(__name__)
+games = {}
+agentclass = None
+
+
+class Agent(dba.DotsAndBoxesAgent):
+ def __init__(self, player, nb_rows, nb_cols, timelimit):
+ super(Agent, self).__init__(player, nb_rows, nb_cols, timelimit)
+ self.GameStateClass = DotsAndBoxesState
+ self.game_state = self.GameStateClass(nb_rows, nb_cols, player)
+ self.controller = MCTSGameController()
+
+ def register_action(self, row, column, orientation, player):
+ super(Agent, self).register_action(row, column, orientation, player)
+ # adjust agent specific board representation
+ move = (row, column, orientation)
+ self.game_state.play_move(move)
+
+ def next_action(self):
+ r, c, o = self.controller.get_next_move(self.game_state, time_allowed=self.timelimit)
+ return r, c, o
+
+ def end_game(self):
+ super(Agent, self).end_game()
+
+
+# Adapted from provided code
+def main(argv=None):
+ global agentclass
+ parser = argparse.ArgumentParser(description='Start agent to play Dots and Boxes')
+ parser.add_argument('--verbose', '-v', action='count', default=0, help='Verbose output')
+ parser.add_argument('--quiet', '-q', action='count', default=0, help='Quiet output')
+ parser.add_argument('port', metavar='PORT', type=int, help='Port to use for server')
+ args = parser.parse_args(argv)
+
+ logger.setLevel(max(logging.INFO - 10 * (args.verbose - args.quiet), logging.DEBUG))
+ logger.addHandler(logging.StreamHandler(sys.stdout))
+
+ agentclass = Agent
+ dba.agentclass = Agent
+ dba.start_server(args.port)
+
+
+if __name__ == "__main__":
+ sys.exit(main())
+
diff --git a/python/dotsandboxes/dotsandboxesagent.py b/python/dotsandboxes/dotsandboxesagent.py
index 9fe6cb8..e7407bf 100644
--- a/python/dotsandboxes/dotsandboxesagent.py
+++ b/python/dotsandboxes/dotsandboxesagent.py
@@ -15,6 +15,11 @@ import asyncio
import websockets
import json
from collections import defaultdict
+<<<<<<< HEAD
+=======
+import random
+
+>>>>>>> f6e623d... change base???
logger = logging.getLogger(__name__)
games = {}
diff --git a/python/dotsandboxes/static/dotsandboxes.html b/python/dotsandboxes/static/dotsandboxes.html
index 4e97508..d250c76 100644
--- a/python/dotsandboxes/static/dotsandboxes.html
+++ b/python/dotsandboxes/static/dotsandboxes.html
@@ -2,6 +2,12 @@
<html>
<html lang="en">
<meta charset="utf-8">
+<<<<<<< HEAD
+=======
+<meta name="author" content="Wannes Meert">
+<meta name="description" content="Dots-and-Boxes game. Part of the Machine Learning: Project course at KU Leuven (Hendrik Blockeel, Wannes Meert).">
+<meta name="keywords" content="artificial intelligence,AI,machine learning,dots and boxes,KU Leuven">
+>>>>>>> f6e623d... change base???
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Dots and Boxes</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
@@ -42,6 +48,12 @@
</div>
</div>
</div>
+<<<<<<< HEAD
+=======
+ <div class="footer">
+ <small>&copy; <a href="https://dtai.cs.kuleuven.be">DTAI Research Group</a>, KU Leuven &mdash; <a href="https://github.com/wannesm/dotsandboxes">Source</a></small>
+ </div>
+>>>>>>> f6e623d... change base???
</div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="dotsandboxes.js"></script>
diff --git a/python/start.sh b/python/start.sh
index 455944d..26a4b70 100755
--- a/python/start.sh
+++ b/python/start.sh
@@ -1,3 +1,4 @@
+<<<<<<< HEAD
#/bin/bash
(cd dotsandboxes; python3 dotsandboxesserver.py 8080) &
python3 agent.py 10001 &
@@ -5,6 +6,12 @@ python3 agent.py 10002 &
echo "Press enter to close all programs"
read TRASH;
+=======
+(cd dotsandboxes; python3 dotsandboxesserver.py 8080) &
+python3 agent.py 10001 &
+python3 agent.py 10002 &
+read -p "Press enter to close all programs."
+>>>>>>> f6e623d... change base???
trap "exit" INT TERM
trap "kill 0" EXIT