コード例 #1
0
ファイル: ethan.py プロジェクト: alexalemi/battleship
def generate_playing_board(duration):
	"""
	Generates a random playing board
	"""
	timeout = time.time() + duration
	random_board_string = util.gen_random_board_str()
	max_score = score(read_board(random_board_string))
	while time.time() < timeout:
		new_random_board_string = util.gen_random_board_str()
		new_score = score(read_board(new_random_board_string))
		if new_score > max_score:
			random_board_string = new_random_board_string
			max_score = new_score
			print max_score
	return random_board_string
コード例 #2
0
def generate_playing_board(duration):
    """
	Generates a random playing board
	"""
    timeout = time.time() + duration
    random_board_string = util.gen_random_board_str()
    max_score = score(read_board(random_board_string))
    while time.time() < timeout:
        new_random_board_string = util.gen_random_board_str()
        new_score = score(read_board(new_random_board_string))
        if new_score > max_score:
            random_board_string = new_random_board_string
            max_score = new_score
            print max_score
    return random_board_string
コード例 #3
0
ファイル: tile.py プロジェクト: alexalemi/battleship
comm = util.Communication()

# first we recieve an init string
logging.debug("Recieve the init string...")
initstring = comm.readline()
turn, opponent = initstring.split(",")

if turn=="0":
    myturn = True
else:
    myturn = False
logging.debug("initstring: %s", initstring)


board = util.gen_random_board_str()
for line in board.splitlines():
    comm.sendline(line)

# Now have the main loop, alternating whether its our
# turn or not

guessno = 0
while True:
    try:
        if myturn:
            # we need to send a guess
            guessx = guessno % 10
            guessy = (guessno // 10) % 10
            guessno += 1
            logging.debug("My guess: (%d, %d)", guessx, guessy)
コード例 #4
0
ファイル: hunter.py プロジェクト: wilangt/bataillenavale
                    level=logging.DEBUG)

comm = util.Communication()

# first we recieve an init string
logging.debug("Recieve the init string...")
initstring = comm.readline()
turn, opponent = initstring.split(",")

if turn == "0":
    myturn = True
else:
    myturn = False
logging.debug("initstring: %s", initstring)

board = util.gen_random_board_str()
for line in board.splitlines():
    comm.sendline(line)

# Now have the main loop, alternating whether its our
# turn or not
guessno = 0

#store whether we are currently hunting or targetting
huntmode = True
# an eventual randomized priority queue that will store our targets
targets = []
guesses = set()
allpos = {(i, j) for i in xrange(10) for j in xrange(10)}

while True: