Exemple #1
0
def mainloop():
    "The main TronBot game loop."

    move_number = 1
    first_move = True

    # Just keep iterating. The generator stops when the game is over.
    for board in tron.Board.generate():

        # Record exactly when we read the board to calculate time remaining.
        start_time = time.time()

        # Some statistics we need are only available on the first move.
        if first_move:
            same_dist = same_distance(board, board.me(), board.them())
            first_move = False

        logging.debug('move %d', move_number)

        # Call the configured strategy to determine the best move.
        # Then update the local state object and log a few details.
        # Finally, submit the move to the engine using the API.
        my_move = which_move(board, start_time, same_dist)

        # Log the move summary and elapsed time.
        elapsed = time.time() - start_time
        logging.debug('chose %s (took %0.3fs)', DIR_NAMES[my_move], elapsed)

        # Submit the move back to the game engine and move to the next.
        tron.move(my_move)
        move_number += 1
Exemple #2
0
def mainloop():
    "The main TronBot game loop."

    move_number = 1
    first_move = True

    # Just keep iterating. The generator stops when the game is over.
    for board in tron.Board.generate():

        # Record exactly when we read the board to calculate time remaining.
        start_time = time.time()

        # Some statistics we need are only available on the first move.
        if first_move:
            same_dist = same_distance(board, board.me(), board.them())
            first_move = False

        logging.debug("move %d", move_number)

        # Call the configured strategy to determine the best move.
        # Then update the local state object and log a few details.
        # Finally, submit the move to the engine using the API.
        my_move = which_move(board, start_time, same_dist)

        # Log the move summary and elapsed time.
        elapsed = time.time() - start_time
        logging.debug("chose %s (took %0.3fs)", DIR_NAMES[my_move], elapsed)

        # Submit the move back to the game engine and move to the next.
        tron.move(my_move)
        move_number += 1
Exemple #3
0
ORDER = list(tron.DIRECTIONS)
random.shuffle(ORDER)

def which_move(board):

    decision = board.moves()[0]

    for dir in ORDER:

        # where we will end up if we move this way
        dest = board.rel(dir)

        # destination is passable?
        if not board.passable(dest):
            continue

        # positions adjacent to the destination
        adj = board.adjacent(dest)

        # if any wall adjacent to the destination
        if any(board[pos] == tron.WALL for pos in adj):
            decision = dir
            break

    return decision

# make a move each turn
for board in tron.Board.generate():
    tron.move(which_move(board))

Exemple #4
0
    for i in ORDER:

        decision = board.moves()[0]

        #looking at area directly surrounding
        landing = board.rel(i)

        #finding legal moves within surrounding area
        if not board.passable(landing):
            continue

        #defining the squares adjacent to chosen legal move (looking 2 steps ahead)
        adj = board.adjacent(landing)

        if any(board[place] == tron.FLOOR for place in adj):
            decision = i
            break

        #for place in adj:
        #defining the squares 3 steps ahead
        #adj2 = board.adjacent(place)
        #if 2 and 3 steps ahead are open, move to the place that allows for that
        #if any (board[place] == tron.FLOOR and
        # ( board[p2] == tron.FLOOR for p2 in adj2 )):

    return decision


for board in tron.Board.generate():
    tron.move(which_move(board))
def main():
  for board in tron.Board.generate():
    tron.move(which_move(board))
Exemple #6
0
	
	elif status.strategy == "near":
		if abs(them_y - me_y) >= abs(them_x - me_x):
			if (them_y < me_y) and NORTH in my_moves:
				return go(NORTH, status.strategy)
			elif (them_y > me_y) and SOUTH in my_moves:
				return go(SOUTH, status.strategy)
			elif (them_x < me_x) and WEST in my_moves:
				return go(WEST, status.strategy)
			elif (them_x > me_x) and EAST in my_moves:
				return go(EAST, status.strategy)
			else:
				direction = random.choice(my_moves)
				return go(direction, "freaking out")
		else:
			if (them_x < me_x) and WEST in my_moves:
				return go(WEST, status.strategy)
			elif (them_x > me_x) and EAST in my_moves:
				return go(EAST, status.strategy)
			elif (them_y < me_y) and NORTH in my_moves:
				return go(NORTH, status.strategy)
			elif (them_y > me_y) and SOUTH in my_moves:
				return go(SOUTH, status.strategy)
			else:
				direction = random.choice(board.moves())
				return go(direction, "freaking out")

# you do not need to modify this part, but I did slightly.
for board in tron.Board.generate():
    tron.move(which_move(board, status))
Exemple #7
0
#        if self.lastDirection is not None \
#                and board.passable(board.rel(self.lastDirection)):
#            debug_move(self.lastDirection)
#            return self.lastDirection

        if self.lastDirection is None:
            self.lastDirection = themDirection

        if not board.passable(board.rel(themDirection)) and \
                not board.passable(board.rel(self.lastDirection)):
            debug("Not them, Not Last, picking random")
            debug_move(self.lastDirection, "Last was: ")
            newDirection = random.choice(board.moves())
        elif not board.passable(board.rel(themDirection)) and \
                board.passable(board.rel(self.lastDirection)):
            debug("Not them, moving last")
            newDirection = self.lastDirection
        else:
            debug("Moving to them")
            newDirection = themDirection

        debug_move(newDirection)
        self.lastDirection = newDirection
        return newDirection

tronguy = TronPlayer()
# you do not need to modify this part
for board in tron.Board.generate():
    tron.move(tronguy.genMove(board))
def main():
    for board in tron.Board.generate():
        tron.move(which_move(board))