Пример #1
0
 def test_spot_counts_init(self):
     config = board.GameConfiguration(6, 2)
     b = board.Board(config, [1, 2, 3])
     self.assertListEqual(list(b.spot_counts), [1, 2, 3])
Пример #2
0
import random
import os
import math
import time
import board as b
import snake as s

snake = s.Snake()
board = b.Board()
board.SpawnPickup(snake.body)


def Distance(x, y):
    tempX = abs(x[0] - y[0])
    tempY = abs(x[1] - y[1])
    return (tempX + tempY)


def PathScores(board, snake, destination):
    tiles = []
    for x in range(10):
        tiles.append([])
        for y in range(10):
            tiles[x].append(Distance(destination, (x, y)))
            if (board[x][y] == "s"):
                tiles[x][y] = 999

    controls = ['w', 's', 'a', 'd']
    scores = []

    head = snake[0]
Пример #3
0
 def test_total_pips(self):
     config = board.GameConfiguration(6, 3)
     self.assertEqual(0, board.Board(config, [6, 0, 0, 0]).total_pips())
     self.assertEqual(5, board.Board(config, [1, 5, 0, 0]).total_pips())
     self.assertEqual(14, board.Board(config, [0, 1, 2, 3]).total_pips())
Пример #4
0
 def test_generate_moves_second_dependent(self):
     config = board.GameConfiguration(2, 4)
     b = board.Board(config, [0, 0, 1, 0, 1])
     got = list(b.generate_moves(board.Roll(dice=[4, 4], prob=0)))
     self.assertEqual(1, len(got))
     self.assertIn([board.Move(4, 4), board.Move(2, 4)], got)
Пример #5
0
import sys
import pytest
sys.path.append("../lib/")
import board as b

test_tiles = ([12, 13], [11, 37], [22, 11], [13, 24], [13, 48], [25, 24])
print("Input: {}".format(test_tiles))
myboard = b.Board(4, 4)
myboard.setTiles(test_tiles)
Пример #6
0
import board
import blocks

new_board = board.Board()

def find_borders(regionID):

	return_list = []

	for element in regionID:

		for i,border in enumerate(board.new_board.static_borders[element]):

			print (board.new_board.static_borders[element])

			if border == "B":

				return_list.append(i)

	return return_list


def check_path(num_moves,startID,endID):

	check_list = [startID]

	for i in range(num_moves):

		if endID in find_borders(check_list):

			return True
Пример #7
0
 def test_count_diagnal(self):
     # 4 x 4 with 3 to win
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # 4 x 4 with 3 to win no diagnal
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[0, 0, 1, 1], [0, 0, 2, 2], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # count top-left to bot-right
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 2, 2, 0], [0, 1, 2, 0], [0, 0, 1, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 0, 1], [0, 1, 0]]
     self.assertEqual(found, expect)
     # count top-right to bot-left
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[0, 2, 1, 0], [2, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 0, 1], [0, 1, 0]]
     self.assertEqual(found, expect)
     # mix of both 4 x 4
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 2, 1, 0], [2, 1, 2, 0], [1, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 1, 1], [0, 2, 0]]
     self.assertEqual(found, expect)
     # mix of both 4 x 1
     w = 4
     h = 1
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1, 2, 1, 0]], w, h, to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # mix of both 1 x 4
     w = 1
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1], [2], [2], [1]], w, h, to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # mix of both 4 x 4 with 4 to win
     w = 4
     h = 4
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 2, 1, 0], [2, 1, 2, 0], [1, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 1, 1, 0], [0, 2, 0, 0]]
     self.assertEqual(found, expect)
     # mix of both 4 x 4 with 4 to win
     w = 4
     h = 4
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 2, 1, 0], [2, 1, 2, 0], [1, 2, 2, 0], [0, 0, 2, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 1, 1, 0], [0, 3, 1, 0]]
     self.assertEqual(found, expect)
     # mix of both 4 x 4 with 6 to win
     w = 6
     h = 3
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 2, 2, 1, 2, 2], [0, 1, 1, 2, 1, 0], [0, 0, 0, 1, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 1, to_win)
     expect = [[0, 5, 0], [0, 2, 0]]
     self.assertEqual(found, expect)
     # change AI to player2
     w = 6
     h = 3
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 2
     b = board.Board(
         [[1, 2, 2, 1, 2, 2], [0, 1, 1, 2, 1, 0], [0, 0, 0, 1, 0, 0]], w, h,
         to_win)
     found = agent.count_diagnal(b, 2, to_win)
     expect = [[0, 2, 0], [0, 5, 0]]
     self.assertEqual(found, expect)
Пример #8
0
    # entirely of the player character, then that
    # player has won.
    #
    # If we end up having found no runs where this player
    # is the only non-blank character, then this player
    # has not won on this round
    #
    run_length = len(b.dimensions[0])
    for coords, data in b.runs_of_n(run_length):
        if all(i == player for i in data):
            return True
    return False


if __name__ == '__main__':
    b = board.Board((N_CELLS, N_CELLS))
    for turn in turns():
        print()
        b.draw()
        coord = get_coord(b, turn)
        b[coord] = turn

        #
        # Check to see if this player has won.
        # We don't need to check all the players, because
        # you can't cause another player to win on your
        # own turn in noughts-and-crosses
        #
        if has_player_won(b, turn):
            print("%s has won!" % turn)
            break
Пример #9
0
 def test_count_horizontal(self):
     # 4 x 4 with 3 to win
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # Two horizontals
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 1, 1, 0], [0, 2, 2, 0], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 0, 1], [0, 1, 0]]
     self.assertEqual(found, expect)
     # larger in a row than to_win
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 1, 1, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 0, 1], [0, 0, 0]]
     self.assertEqual(found, expect)
     # cointing 1s
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 2, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # large rows
     w = 8
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1, 1, 1, 1, 0, 1, 1, 1], [0, 2, 2, 2, 0, 0, 0, 0],
                      [0, 0, 2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]],
                     w, h, to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 0, 2], [0, 1, 1]]
     self.assertEqual(found, expect)
     # change to Player2
     w = 8
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1  # NOTE: count_horizontal will not depend on agent.player
     b = board.Board([[1, 1, 1, 1, 0, 1, 1, 1], [0, 2, 2, 2, 0, 0, 0, 0],
                      [0, 0, 2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]],
                     w, h, to_win)
     found = agent.count_horizontal(b, 2, to_win)
     expect = [[0, 1, 1], [0, 0, 2]]
     self.assertEqual(found, expect)
     # only 1 column
     w = 1
     h = 4
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1], [1], [2], [1]], w, h, to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 0, 0, 0], [0, 0, 0, 0]]
     self.assertEqual(found, expect)
     # only 1 row
     w = 4
     h = 1
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1, 2, 1, 1]], w, h, to_win)
     found = agent.count_horizontal(b, 1, to_win)
     expect = [[0, 1, 0, 0], [0, 0, 0, 0]]
     self.assertEqual(found, expect)
Пример #10
0
 def test_count_vertical(self):
     # 4 x 4 with 3 to win
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 0, 0], [0, 0, 0]]
     self.assertEqual(found, expect)
     # two vertical
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 0, 2, 0], [1, 0, 2, 0], [1, 0, 2, 0], [0, 0, 0, 0]], w, h,
         to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 0, 1], [0, 0, 1]]
     self.assertEqual(found, expect)
     # multi verticals with larger than N to win
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 1, 2, 0], [1, 1, 2, 0], [1, 2, 2, 0], [1, 2, 2, 0]], w, h,
         to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 1, 1], [0, 1, 1]]
     self.assertEqual(found, expect)
     # change AI to player2
     w = 4
     h = 4
     to_win = 3
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 2
     b = board.Board(
         [[1, 1, 2, 0], [1, 1, 2, 0], [1, 2, 2, 0], [1, 2, 2, 0]], w, h,
         to_win)
     found = agent.count_vertical(b, 2, to_win)
     expect = [[0, 1, 1], [0, 1, 1]]
     self.assertEqual(found, expect)
     # 4 to win
     w = 4
     h = 4
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board(
         [[1, 1, 2, 1], [1, 1, 2, 1], [1, 1, 2, 1], [1, 2, 2, 1]], w, h,
         to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 0, 1, 2], [0, 0, 0, 1]]
     self.assertEqual(found, expect)
     # do NOT allow 1-in-a-row
     w = 2
     h = 4
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1, 2], [2, 1], [1, 2], [2, 1]], w, h, to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 0, 0, 0], [0, 0, 0, 0]]
     self.assertEqual(found, expect)
     # only 1 column
     w = 1
     h = 4
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1], [1], [1], [1]], w, h, to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 0, 0, 1], [0, 0, 0, 0]]
     self.assertEqual(found, expect)
     # only 1 row
     w = 4
     h = 1
     to_win = 4
     agent = aba.AlphaBetaAgent("TEST_AI", 1, to_win)
     agent.player = 1
     b = board.Board([[1, 2, 1, 1]], w, h, to_win)
     found = agent.count_vertical(b, 1, to_win)
     expect = [[0, 0, 0, 0], [0, 0, 0, 0]]
     self.assertEqual(found, expect)
Пример #11
0
        car_configs = helper.load_json(filename)
        for item in car_configs.keys():
            new_car = car.Car(item, car_configs[item][0], car_configs[item][1],
                              car_configs[item][2])
            self.__cars.append(new_car)
            self.__board.add_car(new_car)

    def check_args(self, args):
        """
        Check argv
        :param args: arguments list
        :return: String of error if exist, None otherwise
        """
        if len(args) != 1:
            return "Wrong number of arguments"
        elif not os.path.exists(args[0]):
            return "File does not exist"
        return None


if __name__ == "__main__":
    print(sys.argv)
    args = sys.argv[1:]
    rush_game = Game(board.Board())
    args_check = rush_game.check_args(args)
    if args_check != None:
        print(args_check)
    else:
        rush_game.upload_cars(args[0])
        rush_game.play()
Пример #12
0
 def __init__(self, board_size):
     self.board = board.Board(board_size)
     self.players = []
Пример #13
0
    def apply_to(self, b):
        new_board = board.Board(b.width, b.height, b.iteration, b.rules)

        b.for_each(lambda x, y, c: self.apply_rules(b, new_board, x, y, c))

        b.cells = new_board.cells
Пример #14
0
def init_game():
    """
    Initialize the game with map, players and bank
    1. generate a map
    2. initialize players
    3. initialize bank
    all of the data
    :return: map, players list and bank
    """
    # generate a map
    parent_addr = os.path.abspath(os.pardir)
    block_list_data = json_reader(
        os.path.join(parent_addr, 'Data/block_data.json'))
    station_list_data = json_reader(
        os.path.join(parent_addr, 'Data/station_data.json'))
    utility_list_data = json_reader(
        os.path.join(parent_addr, 'Data/utility_data.json'))
    estate_list_data = json_reader(
        os.path.join(parent_addr, 'Data/estate_data.json'))
    chest_list_data = json_reader(
        os.path.join(parent_addr, 'Data/chest_data.json'))
    chance_list_data = json_reader(
        os.path.join(parent_addr, 'Data/chance_data.json'))
    block_list = [0 for x in range(40)]
    station_list = []
    utility_list = []
    estate_list = []
    corner_list = []
    chest_block_list = []
    chance_block_list = []
    tax_list = []

    # initialize bank
    epic_bank = bank.Bank('99', 'EpicBank', 32, 12)
    json_writer(os.path.join(parent_addr, 'Data/bank_data.json'), {
        "house_number": epic_bank.cur_house,
        "hotel_number": epic_bank.cur_hotel
    })

    for b in block_list_data["data"]:
        if b['block_type'] == 0:
            # ["Go", "Go to Jail", "In Jail", "Free Parking"]
            if b['name'] == "Go":
                corner_block = block.Go(b['name'], b['block_id'],
                                        b['position'])
            elif b['name'] == "Go to Jail":
                corner_block = block.Go_To_Jail(b['name'], b['block_id'],
                                                b['position'])
            elif b['name'] == "In Jail":
                corner_block = block.In_Jail(b['name'], b['block_id'],
                                             b['position'])
            elif b['name'] == "Free Parking":
                corner_block = block.Free_Parking(b['name'], b['block_id'],
                                                  b['position'])
            else:
                pass
            block_list[corner_block.position] = corner_block
            corner_list.append(corner_block)
        elif b['name'] == "Community Chest":
            # "Community Chest"
            new_block = cardpile.Community_Chest(b['name'], b['block_id'],
                                                 b['position'])
            block_list[new_block.position] = new_block
            chest_block_list.append(new_block)
        elif b['name'] == "Chance":  # "Chance"
            new_block = cardpile.Chance(b['name'], b['block_id'],
                                        b['position'])
            block_list[new_block.position] = new_block
            chance_block_list.append(new_block)
        elif b['block_type'] == 3:
            # ["Income Tax", "Super Tax"]
            if b['name'] == "Income Tax":
                new_block = tax.Income_Tax(b['name'], b['block_id'],
                                           b['position'], 0.10)
            elif b['name'] == "Super Tax":
                new_block = tax.Super_Tax(b['name'], b['block_id'],
                                          b['position'], 0.10)
            else:
                pass
            block_list[new_block.position] = new_block
            tax_list.append(new_block)
    # name, position, uid, estate_value, status, street_id
    for s in station_list_data["data"]:
        new_block = station.Station(s['name'], s['block_id'], s['position'],
                                    s['uid'], s['estate_value'], s['status'])
        station_list.append(new_block)
        block_list[new_block.position] = new_block
        epic_bank.add_asset(new_block)
    # name, position, uid, estate_value, status, street_id
    for u in utility_list_data["data"]:
        new_block = utility.Utility(u['name'], u['block_id'], u['position'],
                                    u['uid'], u['estate_value'], u['status'])
        utility_list.append(new_block)
        block_list[new_block.position] = new_block
        epic_bank.add_asset(new_block)
    for e in estate_list_data["data"]:
        new_block = estate.Estate(e['name'], e['block_id'], e['position'],
                                  e['uid'], e['estate_value'], e['status'],
                                  e['street_id'], e['house_value'])
        estate_list.append(new_block)
        block_list[new_block.position] = new_block
        epic_bank.add_asset(new_block)

    # initialize players
    player_dict_data = json_reader(
        os.path.join(parent_addr, 'Data/player_list.json'))
    player_dict = {}
    player_dict_data = player_dict_data["data"]
    for i in range(len(player_dict_data)):
        p = player.Player(player_dict_data[i]['id'],
                          player_dict_data[i]['name'],
                          player_dict_data[i]['cash'],
                          player_dict_data[i]['alliance'])
        out_put_line = "%d %d %s %s" % (p.cash, p.id, p.name, p.alliance)
        operation.push2all(out_put_line)
        player_dict[player_dict_data[i]['id']] = p

    # initialize chest cards
    chest_list = []
    for chest in chest_list_data["data"]:
        # 0: Collection, 1: Collect_from_players
        if chest['card_type'] == 0 or chest['card_type'] == 1:
            chest_list.append(
                card.CollectCard(chest['card_id'], chest['card_type'],
                                 chest['description'], chest['amount']))
        elif chest['card_type'] == 2 or chest[
                'card_type'] == 3:  # 2: Pay, 3: Pay_for_repair
            # or chest['card_type'] == 8 8: Pay_to_players
            chest_list.append(
                card.PayCard(chest['card_id'], chest['card_type'],
                             chest['description'], chest['amount']))
        # elif chest['card_type'] == 4 or chest['card_type'] == 6:  # 4: Move_indicate_position, 6: Move_nearby
        #     chest_list.append(card.MoveCard(chest['card_id'], chest['card_type'], chest['description'],
        #                                     chest['block_id']))
        # elif chest['card_type'] == 7:  # Move
        #     chest_list.append(card.MoveCard(chest['card_id'], chest['card_type'], chest['description'],
        #                                     chest['steps']))
        elif chest['card_type'] == 5:  # Bailcard
            chest_list.append(
                card.BailCard(chest['card_id'], chest['card_type'],
                              chest['description']))

    # initialize chance cards
    chance_list = []
    for chance in chance_list_data["data"]:
        if chance['card_type'] == 0:  # 0: Collection
            # or chance['card_type'] == 1, 1: Collect_from_players
            chance_list.append(
                card.CollectCard(chance['card_id'], chance['card_type'],
                                 chance['description'], chance['amount']))
        elif chance['card_type'] == 2 or chance['card_type'] == 3 or chance[
                'card_type'] == 8:  # 2: Pay,
            # 3: Pay_for_repair
            # 8: Pay_to_players
            chance_list.append(
                card.PayCard(chance['card_id'], chance['card_type'],
                             chance['description'], chance['amount']))
        # 4: Move_indicate_position, 6: Move_nearby
        elif chance['card_type'] == 4 or chance['card_type'] == 6:
            chance_list.append(
                card.MoveCard(chance['card_id'], chance['card_type'],
                              chance['description'], chance['block_id']))
        elif chance['card_type'] == 7:  # Move
            chance_list.append(
                card.MoveCard(chance['card_id'], chance['card_type'],
                              chance['description'], chance['steps']))
        elif chance['card_type'] == 5:  # Bailcard
            chance_list.append(
                card.BailCard(chance['card_id'], chance['card_type'],
                              chance['description']))

    # initialize chess board
    two_block_street = []
    three_block_street = []
    for e in estate_list:
        if e.street_id == 1 or e.street_id == 8:
            two_block_street.append(e)
        else:
            three_block_street.append(e)
    chess_board_object = board.Board(two_block_street, three_block_street,
                                     station_list, utility_list, block_list,
                                     corner_list, chest_block_list,
                                     chance_block_list, tax_list)

    global data
    data['chess_board'] = block_list
    data['player_dict'] = player_dict
    data['epic_bank'] = epic_bank
    data['chest_list'] = chest_list
    data['chance_list'] = chance_list
    data['station_list'] = station_list
    data['utility_list'] = utility_list
    data['estate_list'] = estate_list
    data['corner_list'] = corner_list
    data['chest_block_list'] = chest_block_list
    data['chance_block_list'] = chance_block_list
    data['tax_list'] = tax_list
    return data
Пример #15
0
    def test_num_in_a_row(self):
        # control
        n_to_win = 2
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        b = board.Board(
            [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)
        result = agent.num_in_a_row(b)
        expect = 0
        self.assertEqual(result, expect)
        # only vertical
        n_to_win = 2
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board(
            [[0, 2, 0, 0], [0, 2, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)
        result = agent.num_in_a_row(b)
        expect = -2
        self.assertEqual(result, expect)
        # same weight for both players
        n_to_win = 4
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board(
            [[0, 2, 0, 1], [0, 2, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)
        result = agent.num_in_a_row(b)
        expect = 0
        self.assertEqual(result, expect)

        n_to_win = 4
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board(
            [[0, 0, 1, 1], [0, 0, 2, 2], [0, 0, 0, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)
        result = agent.num_in_a_row(b)
        expect = 0
        self.assertEqual(result, expect)
        # only horizontal
        n_to_win = 4
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board(
            [[1, 1, 1, 1], [0, 0, 2, 2], [0, 0, 0, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)
        result = agent.num_in_a_row(b)
        expect = 2
        self.assertEqual(result, expect)
        # only diagnal
        n_to_win = 4
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board(
            [[1, 0, 0, 1], [0, 1, 2, 0], [0, 2, 1, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)
        result = agent.num_in_a_row(b)
        expect = 1
        self.assertEqual(result, expect)
        # mix
        n_to_win = 4
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board(
            [[1, 2, 2, 1], [0, 1, 2, 0], [0, 2, 1, 0], [0, 0, 0, 0]], 4, 4,
            n_to_win)

        result = agent.num_in_a_row(b)
        expect = -5
        self.assertEqual(result, expect)
        n_to_win = 7
        agent = aba.AlphaBetaAgent("TEST_AI", 1, n_to_win)
        agent.player = 1
        agent.quad_scalar = lambda x: x
        b = board.Board([[1, 2, 2, 1, 1], [0, 1, 2, 1, 2], [0, 2, 1, 0, 1],
                         [0, 0, 0, 0, 0]], 5, 4, n_to_win)
        result = agent.num_in_a_row(b)
        expect = 4
        self.assertEqual(result, expect)
Пример #16
0
import board, ai_player, game_controller

board = board.Board()

# player1 = AIPlayer.AIPlayer(board)
# player2 = None
#
# if True:
#     player2 = AIPlayer.AIPlayer(board)
#
#     player1.getAnOpponent(player2)
#     player2.getAnOpponent(player1)
#
#     GameController.GameController.startGame(player1, player2)
Пример #17
0
import board

BOARDSIZE = 9

board = board.Board(BOARDSIZE)
Пример #18
0
char1_pos = (1, 3)
char1 = chr.Character(chars_sprites[0], char_offset, mov_handler)
char2_pos = (1, 1)
char2 = chr.Character(chars_sprites[1], char_offset, mov_handler)
characters = [char1, char2]

# Builds boards
field1 = [[0, 1, 2, 4, 5], [10, -22, -22, -22, 15], [20, -22, 50, 51, 45],
          [30, -22, 15, 78, 78], [40, 41, 45, 78, 78]]
obj1 = (3, 1)
field2 = [[0, 1, 5, 78, 78], [10, -22, 15, 78, 78], [20, -22, 1, 2, 5],
          [30, -22, -22, -22, 35], [40, 41, 42, 44, 45]]
obj2 = (3, 3)
boards = [
    bd.Board(5, 5, [(char1, char1_pos)], [obj1], field1),
    bd.Board(5, 5, [(char2, char2_pos)], [obj2], field2)
]

# Main loop
while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:  #close screen command
            done = True
        if event.type == pg.KEYDOWN and event.key in [
                pg.K_UP, pg.K_DOWN, pg.K_LEFT, pg.K_RIGHT
        ]:
            most_recent_mov_key = event.key
            first_mov_of_keystrike = True

    twice = 1  #executes again if ends not moving after first iteration
Пример #19
0
import os
import random
import string

import board

b2 = board.Board((3, 3))
b3 = board.Board((4, 4, 4))
bi = board.Board((4, board.Infinity))

for coord in b2:
    b2[coord] = random.choice(string.ascii_uppercase)
for coord in b3:
    b3[coord] = random.choice(string.ascii_uppercase)
bi.populate(range(100))
Пример #20
0
    def __init__(self):
        self.board = board.Board()
        self.white = players.Human
        self.black = players.Human
        self.history = deque()
        self.moves = 0
        self.state = self.menu
        self.result = ''
        self.difficulty = 2

        self.menuButtons = [
            ButtonArray(win,
                        80,
                        200,
                        720,
                        200, (2, 1),
                        topBorder=20,
                        bottomBorder=20,
                        leftBorder=100,
                        rightBorder=100,
                        separationThickness=200,
                        borderRadius=20,
                        inactiveColours=(WHITE, BLACK),
                        pressedColours=(LIGHT_GREY, GREY),
                        images=(HUMAN_ICON, HUMAN_ICON),
                        radii=(20, 20),
                        hoverColours=(LIGHT_GREY, GREY),
                        onReleases=(self.selectComputer, self.selectComputer),
                        onReleaseParams=((WHITE, ), (BLACK, ))),
            ButtonArray(win,
                        80,
                        500,
                        720,
                        100, (4, 1),
                        topBorder=10,
                        bottomBorder=10,
                        leftBorder=80,
                        rightBorder=80,
                        separationThickness=80,
                        borderRadius=20,
                        texts=('1', '2', '3', '4'),
                        fontSizes=(40, 40, 40, 40),
                        inactiveColours=(RED, GREEN, RED, RED),
                        pressedColours=(RED, GREEN, RED, RED),
                        hoverColours=(DARK_RED, DARK_GREEN, DARK_RED,
                                      DARK_RED),
                        onClicks=(self.selectDifficulty, self.selectDifficulty,
                                  self.selectDifficulty,
                                  self.selectDifficulty),
                        onClickParams=((1, ), (2, ), (3, ), (4, )),
                        radii=(40, 40, 40, 40)),
            Button(win,
                   30,
                   700,
                   820,
                   150,
                   inactiveColour=ORANGE,
                   hoverColour=DARK_ORANGE,
                   onClick=self.startGame,
                   text='Start',
                   font=START,
                   radius=30)
        ]

        self.endButtons = [
            Button(win,
                   30,
                   700,
                   820,
                   150,
                   inactiveColour=ORANGE,
                   hoverColour=DARK_ORANGE,
                   pressedColour=DARK_ORANGE,
                   onRelease=self.showMenu,
                   text='Play Again?',
                   font=START,
                   radius=30)
        ]
Пример #21
0
def main():
    pos = board.Board(chess.STARTING_FEN)

    engine = capture_bot.CaptureBot()

    our_time, opp_time = 1000, 1000  # time in centi-seconds

    # print name of chess engine
    print('CHESSBOT VORAPSAK')

    cmdstack = []
    while True:
        if cmdstack:
            cmd = cmdstack.pop()
        else:
            cmd = input()

        if cmd == 'quit':
            break

        elif cmd == 'uci':
            print('uciok')

        elif cmd == 'isready':
            print('readyok')

        elif cmd == 'ucinewgame':
            cmdstack.append('position fen ' + chess.STARTING_FEN)

        elif cmd.startswith('position'):
            params = cmd.split(' ', 2)
            if params[1] == 'fen':
                fen = params[2]
                pos = chess.Board(fen)

        elif cmd.startswith('go'):
            # parse parameters
            params = cmd.split(' ')
            if len(params) == 1:
                continue

            # startthink = time.time()

            move = engine.choose_move(pos)

            # endthink = time.time()

            # We only resign once we are mated.. That's never?
            pos.push(move)
            if pos.is_game_over():
                print('resign')
            else:
                print('bestmove ' + move.uci())

        elif cmd.startswith('time'):
            our_time = int(cmd.split()[1])

        elif cmd.startswith('otim'):
            opp_time = int(cmd.split()[1])

        else:
            pass