aboutsummaryrefslogtreecommitdiffstats
path: root/python/agent_AB.py
diff options
context:
space:
mode:
authorMatt Strapp <strap012@umn.edu>2021-04-26 17:12:01 -0500
committerMatt Strapp <strap012@umn.edu>2021-04-26 17:12:01 -0500
commita093060b0e8a787e51212b5f2879dc839605da65 (patch)
tree7ec2d69219d41ae6447efc41ebaaac34c696984b /python/agent_AB.py
parentRefactor jsut about everything (diff)
downloadcsci4511w-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 'python/agent_AB.py')
-rw-r--r--python/agent_AB.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/python/agent_AB.py b/python/agent_AB.py
new file mode 100644
index 0000000..5564f11
--- /dev/null
+++ b/python/agent_AB.py
@@ -0,0 +1,57 @@
+from python.alphaBeta import AlphaBeta
+import dotsandboxes.dotsandboxesagent as dba
+
+import sys
+import argparse
+import logging
+from GameState import GameState, DotsAndBoxesState
+import alphaBeta
+
+
+logger = logging.getLogger(__name__)
+games = {}
+agentclass = dba
+
+
+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 = AlphaBeta()
+
+ 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)
+ print(args)
+
+ 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())
+