Ejemplo n.º 1
0
    def test8(self):
        #shallow test (on small board) to ensure alphabeta is running faster (& therefore pruning) in comparison to minimax
        depth = 5

        p1 = makePlayer("m", "x", depth)
        p2 = makePlayer("a", "x", depth)

        board = [["x", " ", "x", "o", "x",
                  "o"], [" ", "x", "o", "x", "o", "x"],
                 [" ", "o", "x", "o", "x",
                  "o"], ["o", "x", "o", "x", "o", "x"],
                 ["x", "o", "x", "o", "x", "o"],
                 ["o", "x", "o", "x", "o", "x"]]
        import time as t

        minimaxStartTime = t.time()
        minimaxMove = p1.getMove(board)
        minimaxEndTime = (t.time() - minimaxStartTime)

        alphabetaStartTime = t.time()
        alphabetaMove = p2.getMove(board)
        alphabetaEndTime = (t.time() - alphabetaStartTime)

        print("\nminimaxEndTime and alphabetaEndTime differed by: " +
              str(minimaxEndTime - alphabetaEndTime) + " seconds\n")
        self.assertTrue(minimaxEndTime > alphabetaEndTime)
Ejemplo n.º 2
0
def MakeBoard(p1, p2):
    iterations = 1 
    depth = 3
    rows, cols = 10, 10
    gm = game_manager.GameManager(rows, cols, player.makePlayer(p1, 'x', depth), player.makePlayer(p2, 'o', depth), True)

    return gm
Ejemplo n.º 3
0
 def makeGame(self, size, player1, player2, depth):
     gm = game_manager.GameManager(size, size,
                                   makePlayer(player1, 'x', depth),
                                   makePlayer(player2, 'o', depth), False)
     signal.signal(signal.SIGABRT, gm.interrupt)
     signal.signal(signal.SIGINT, gm.interrupt)
     signal.signal(signal.SIGQUIT, gm.interrupt)
     signal.signal(signal.SIGALRM, gm.interrupt)
     return gm
Ejemplo n.º 4
0
def MakeBoard(p1, p2):
    iterations = 1
    depth = 3
    rows, cols = 10, 10
    gm = game_manager.GameManager(rows, cols,
                                  player.makePlayer(p1, 'x', depth),
                                  player.makePlayer(p2, 'o', depth), True)
    signal.signal(signal.SIGABRT, gm.interrupt)
    signal.signal(signal.SIGINT, gm.interrupt)
    signal.signal(signal.SIGQUIT, gm.interrupt)

    return gm
Ejemplo n.º 5
0
    def test7(self):
        #shallow test (on small board) to ensure minimax is returning the proper move @ certain depth w/o running whole game simulation
        #tree has 2 winning moves for X, should choose first one it sees
        #actually passed this before passing test1 due to python version differences, which added to my confusion at the time
        depth = 2
        p1 = makePlayer("m", "x", depth)

        board = [["x", "o", "x", "x"], ["o", "x", " ", " "],
                 [" ", "o", " ", "o"], [" ", " ", " ", "x"]]
        move = p1.getMove(board)
        self.assertEqual(((0, 0), (2, 0)), move)
Ejemplo n.º 6
0
 def makeGame(self, size, player1, player2, depth, script=None):
     gm = game_manager.GameManager(size, size,
                                   makePlayer(player1, 'x', depth),
                                   makePlayer(player2, 'o', depth), script,
                                   True)
     return gm
Ejemplo n.º 7
0
###########################################################################

from docopt import docopt
from player import makePlayer

import game_manager
import signal

if __name__ == "__main__":
  arguments = docopt(__doc__, version="Konane v1.0")
  iterations = int(arguments["--iterations"])
  timeout = int(arguments["--timeout"])
  rows = int(arguments["--rows"])
  cols = int(arguments["--cols"])
  p1 = arguments["-1"].capitalize()
  p2 = arguments["-2"].capitalize()
  gm = game_manager.GameManager(rows, cols
                                , makePlayer(p1, 'x', timeout)
                                , makePlayer(p2, 'o', timeout)
                                , "--verbose" in arguments and arguments["--verbose"])
  signal.signal(signal.SIGABRT, gm.interrupt)
  signal.signal(signal.SIGINT, gm.interrupt)
  signal.signal(signal.SIGQUIT, gm.interrupt)
  for _ in range(int(arguments["--iterations"])):
    gm.reset()
    gm.play()
    if gm.state == game_manager.X_VICTORY:
      print("X Wins!!")
    if gm.state == game_manager.O_VICTORY:
      print("O Wins!!")