Exemple #1
0
def setupRobots():

   retry_autostart = conf.I('game','retry_autostart')
   autostart = False
   if conf.S('game','autostart') == 'True':
      autostart = True

   #Both boards should just be in the same class.
   gameBoard = Board()
   captureBoard1 = CaptureBoard()
   captureBoard2 = CaptureBoard()

   #Setup Robots
   RL = RobotList(2)
   robotList = None
   while True:
      robotList = RL.getList()
      if robotList is False and autostart:
         retry_autostart -= 1
         #try again to get serial ports
         RL.serial_ports()
         if retry_autostart <= 0:
            logging.error("Unable to find robots on start")
            break
         sleep(3)
      elif not autostart:
         break
      else:
         break
     
   if robotList is False:
      print("Found to many or not enough robots to start." \
         "\nChange the number of robots in RobotList in run.py if testing.")
      quit()

   # Robots share the same board 
   robot = Robot(robotList[0],gameBoard,captureBoard1,"white")
   GPIO.add_event_detect(1, GPIO.BOTH, pauseGame)
   robot2 = Robot(robotList[1],gameBoard,captureBoard2, "black")

   # Check to verify the robots are not switched
   robot1ID = conf.S('robotIdents','robot1')
   logging.debug("Robot1 %s"%robot1ID)
   robot2ID = conf.S('robotIdents','robot2')
   logging.debug("Robot2 %s"%robot2ID)

   # Switch the robots if they look incorrect
   if not robot.checkID(robot1ID):
      logging.debug("switching robots")
      tmpRobot = robot2
      robot2 = robot
      robot = tmpRobot

   # Sanity check to make sure they match up after switch
   if robot.checkID(robot1ID):
      logging.error("Unable to identify robot 1!")
   if robot2.checkID(robot2ID):
      logging.error("Unable to identify robot 2!")

   return robot, robot2
Exemple #2
0
def testRobotSetup():
    gameBoard = Board(test=True)
    captureBoard1 = CaptureBoard()
    captureBoard2 = CaptureBoard()
    # Robots share the same board 
    robot = Robot(None, gameBoard, captureBoard1, ROBOT_1_COLOR, test=True)
    robot2 = Robot(None, gameBoard, captureBoard2, ROBOT_2_COLOR, test=True)
    return robot, robot2
Exemple #3
0
def setupRobots():
    #Both boards should just be in the same class.
    gameBoard = Board()
    captureBoard1 = CaptureBoard()
    captureBoard2 = CaptureBoard()

    #Setup Robots
    RL = RobotList(2)
    robotList = RL.getList()
    if robotList is False:
        quit()

    # Robots share the same board
    robot = Robot(robotList[0], gameBoard, captureBoard1, "gold")
    GPIO.add_event_detect(1, GPIO.BOTH, robot.resetBoard)
    robot2 = Robot(robotList[1], gameBoard, captureBoard2, "silver")

    # Check to verify the robots are not switched
    robot1ID = conf.S('robotIdents', 'robot1')
    logging.debug("Robot1 %s" % robot1ID)
    robot2ID = conf.S('robotIdents', 'robot2')
    logging.debug("Robot2 %s" % robot2ID)

    # Switch the robots if they look incorrect
    if not robot.checkID(robot1ID):
        logging.debug("switching robots")
        tmpRobot = robot2
        robot2 = robot
        robot = tmpRobot

    # Sanity check to make sure they match up after switch
    if robot.checkID(robot1ID):
        logging.error("Unable to identify robot 1!")
    if robot2.checkID(robot2ID):
        logging.error("Unable to identify robot 2!")

    return robot, robot2
Exemple #4
0
def setupRobots():
   #Both boards should just be in the same class.
   gameBoard = Board()
   captureBoard = CaptureBoard()

   #Setup Robots
   RL = RobotList(2)
   robotList = RL.getList()
   if robotList is False:
      quit()

   # Robots share the same board 
   robot = Robot(robotList[0],gameBoard,captureBoard)
   robot2 = Robot(robotList[1],gameBoard,captureBoard)
   return robot, robot2
Exemple #5
0
#! /usr/bin/python3

from captureBoard import CaptureBoard
cp = CaptureBoard()

print("==========INSERT==========")
for x in range(0, 16):
    pos = cp.insertNextPos("king%d" % x)
    print("x:%d y:%d cBoardX:%d cBoardY:%d" %
          (pos.getX(), pos.getY(), pos.getXBoard(), pos.getYBoard()))
print(cp.getBoard())

print("==========POPPING==========")
for x in range(0, 16):
    pos = cp.popLast()
    print("x:%d y:%d cBoardX:%d cBoardY:%d" %
          (pos.getX(), pos.getY(), pos.getXBoard(), pos.getYBoard()))
print(cp.getBoard())

print("==========INSERT==========")
for x in range(0, 16):
    pos = cp.insertNextPos("king%d" % x)
    print("x:%d y:%d cBoardX:%d cBoardY:%d" %
          (pos.getX(), pos.getY(), pos.getXBoard(), pos.getYBoard()))
print(cp.getBoard())

print("==========RESET==========")
cp.resetBoard()
print(cp.getBoard())

print("==========INSERT==========")