def test_update_state():
    game = game_state()

    assert game.current_round is None
    assert game.population is None
    assert game.cities == []

    with open('update_state_test_1.txt') as data:
        data = str(data.read())
        data = ast.literal_eval(data)

    game.update_state(data)
    assert game.population is not None
    assert game.points == 40
    assert game.cities[0].name == 'Abuja'
    assert game.cities[0].connections == [
        'Boston', 'Roma', 'Melbourne', 'Warszawa', 'Libreville'
    ]
    assert game.cities[1].name == 'Accra'
    assert game.cities[1].economy == 2

    assert game.current_round == 1
    assert game.population == 1594 + 2750

    with open('update_state_test_2.txt') as data2:
        data2 = str(data2.read())
        data2 = ast.literal_eval(data2)

    game.update_state(data2)

    assert game.population == 1494 + 1750
    assert game.population_reduction is not None
    assert game.population_reduction == (1494 + 1750) / (1594 + 2750)
    assert game.points == 55
def test_neighbor_cities():
    with open('update_state_test_1.txt', 'r') as data:
        data = data.read()
        data = ast.literal_eval(data)

    game = game_state()
    game.update_state(data)

    accra = [x for x in game.cities if x.name == 'Accra'][0]
    assert game.find_neighbor_cities(accra, 4) == []
    assert game.find_neighbor_cities(accra) == ['Abuja']
def move():
    data = bottle.request.json

    # TODO: Do things with data

    #directions = ['up', 'down', 'left', 'right']
    gs = game_state(data)
    #direction = flood_fill(gs, 20)
    direction = 'left'
    print direction
    return {'move': direction, 'taunt': 'battlesnake-python!'}
Пример #4
0
    def start_game(self, src):

        if self.game_start_check():
            player_num = int(self.cb_players_num.get_item())
            names = []
            for i in range(player_num):
                pn = self.tb_players[i].text
                names.append(pn)

            from game_state import game_state

            if self.cb_superhero_pick.checked:
                state = game_state(names)
                self.viewport.push(state)
            else:
                picks = {}
                for i in range(player_num):
                    picks[names[i]] = self.slider_player_superhero[i].get_item()

                state = game_state(names, game_state.ChosenPick, picks)
                self.viewport.push(state)
def test_distance():
    with open('update_state_test_1.txt', 'r') as data:
        data = data.read()
        data = ast.literal_eval(data)

    game = game_state()
    game.update_state(data)

    city1 = game.cities[0]
    city2 = game.cities[1]

    assert game.distance(city1, city2) is not None
    assert game.distance(city1, city2) == 8.35
Пример #6
0
    def start_game(self, src):

        if self.game_start_check():
            player_num = int(self.cb_players_num.get_item())
            names = []
            for i in range(player_num):
                pn = self.tb_players[i].text
                names.append(pn)

            from game_state import game_state

            if self.cb_superhero_pick.checked:
                state = game_state(names)
                self.viewport.push(state)
            else:
                picks = {}
                for i in range(player_num):
                    picks[
                        names[i]] = self.slider_player_superhero[i].get_item()

                state = game_state(names, game_state.ChosenPick, picks)
                self.viewport.push(state)
Пример #7
0
def test_create_p_list():
    with open('data_test_1.txt', encoding="utf8") as data:
        data = str(data.read())
        data = ast.literal_eval(data)

    game = game_state()
    game.update_state(data)

    assert td.create_priority_list(game) is not None
    p_list = td.create_priority_list(game)
    data2 = td.create_data(p_list)
    td.save_data(data2)
    td.possible_actions(game.points, p_list)
Пример #8
0
import socket
import sys

from Validator import Validator
from Exceptions import Not_A_Possible_Input_Or_Not_In_Array_Size, Not_An_Integer, Place_Is_Cover
Validator = Validator()

from draw_board import draw_board
board = draw_board()

from game_state import game_state
state = game_state()

from computer_player import computer_player
computer = computer_player()

import random

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

server_address = ('localhost', 10000)
sys.stderr.write('starting up on %s port %s' % server_address)
sock.bind(server_address)

sock.listen(1)

while True:
    sys.stderr.write(' \nwaiting for a connection')
    connection, client_address = sock.accept()
    if connection or client_address:
        break
Пример #9
0
	def __init__(self, tdlearner, player_one, player_two):
		self.player_one = player_one
		self.player_two = player_two

		# create a game state object
		self.game_state = game_state(self.results(), tdlearner)
Пример #10
0
# execute the learner
if __name__ == "__main__":
	def pad_zeroes(num):
		if num < 1000:
			if num < 100:
				if num < 10:
					return "000" + str(num)
				else:
					return "00" + str(num)
			else:
				return "0" + str(num)
		return str(num)

	# create the tdlearner class to pass to the game walker
	tdl = tdlearner(game_state("B"))

	for i in xrange(0, 100):
		for j in xrange(0, 5000):
			# load and store the game
			fp = open("games/" + pad_zeroes(i), "r")
			moves = fp.readlines()
			fp.close()

			# generate players
			passive_player_black = passive_player("B", moves)
			passive_player_white = passive_player("W", moves, True)

			g = game(tdl, passive_player_black, passive_player_white)
			while not g.at_end():
				move = g.step()
    }


@bottle.post('/move')
def move():
    data = bottle.request.json

    # TODO: Do things with data

    #directions = ['up', 'down', 'left', 'right']
    gs = game_state(data)
    #direction = flood_fill(gs, 20)
    direction = 'left'
    print direction
    return {'move': direction, 'taunt': 'battlesnake-python!'}


# Expose WSGI app (so gunicorn can find it)
application = bottle.default_app()

if __name__ == '__main__':
    gs = game_state(game_state.get_example_raw())
    direction = flood_fill(gs, 10)
    print direction
    bottle.run(application,
               host=os.getenv('IP', '0.0.0.0'),
               port=os.getenv('PORT', '8080'),
               debug=True)
    print "main.py"
    bottle.post(game_state.get_example_raw())