Exemplo n.º 1
0
 def __init__(self, xmax, ymax, nb_feux, nb_pompiers):
     self.board = Board(xmax, ymax, nb_feux)
     self.pompiers = [
         Pompier(i,
                 (random.randint(0, xmax - 1), random.randint(0, xmax - 1)),
                 self.board) for i in range(nb_pompiers)
     ]
Exemplo n.º 2
0
class A1:
    def __init__(self):
        self.zombies = [Actor.Zombie()]
        self.plants = [Actor.Plant(), Actor.Plant()]
        self.Board = Board()
        #self.plants[0].Position.x = 200
        if self.Board.putPlant(0, 1):
            self.plants[0].setPosition(self.Board.getPosition(0, 1))
        if self.Board.putPlant(0, 0):
            self.plants[1].setPosition(self.Board.getPosition(0, 0))

    def getActors(self):
        return (self.zombies, self.plants)

    def run(self):
        for zombie in self.zombies:
            if self.plants:
                if (zombie.isBlocked(self.plants[0])):
                    zombie.attack(self.plants[0])
                    if self.plants[0].isDead():
                        self.plants.remove(self.plants[0])
                else:
                    zombie.move()
            else:
                zombie.move()
Exemplo n.º 3
0
 def __init__(self):
     self.zombies = [Actor.Zombie()]
     self.plants = [Actor.Plant(), Actor.Plant()]
     self.Board = Board()
     #self.plants[0].Position.x = 200
     if self.Board.putPlant(0, 1):
         self.plants[0].setPosition(self.Board.getPosition(0, 1))
     if self.Board.putPlant(0, 0):
         self.plants[1].setPosition(self.Board.getPosition(0, 0))
Exemplo n.º 4
0
 def default(self):
     """
         input : None
         function: Create a game environment for default
         output: None
     """
     self.board = Board(6, 7)
     self.board.create()
     self.board_printer = BoardPrinter(self.system, "bringht", "", "white")
     self.board_printer.load_boar(self.board.column_size)
Exemplo n.º 5
0
def test_create():
    board = Board(6, 7)
    board.create()
    matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
              [' ', ' ', ' ', ' ', ' ', ' ', ' '],
              [' ', ' ', ' ', ' ', ' ', ' ', ' '],
              [' ', ' ', ' ', ' ', ' ', ' ', ' '],
              [' ', ' ', ' ', ' ', ' ', ' ', ' '],
              [' ', ' ', ' ', ' ', ' ', ' ', ' ']]
    
    assert(board.matrix == matrix)
Exemplo n.º 6
0
def test_minimax_Secuential():
    secuential = Secuential(1, '1', '2')
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', '2'],
                    [' ', ' ', ' ', ' ', ' ', ' ', '1'],
                    [' ', ' ', '2', ' ', ' ', '1', '1'],
                    ['2', '1', '2', '2', '2', '1', '1']]
    best_move = secuential.heuristic(board)
    assert (best_move == 114)
Exemplo n.º 7
0
def test_Block_3_check_diagonals_count_2():
    block = Block_3_In_Line_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', '2', ' ', ' ', ' ', ' ', ' '],
                    ['1', '1', ' ', ' ', '2', ' ', ' '],
                    ['2', '1', ' ', '1', '2', '1', '1'],
                    ['1', '2', '2', '1', '2', '1', '1']]
    best_move = block.check_diagonals_count(board, 4, 3, '1', 3)
    assert (best_move == 2)
Exemplo n.º 8
0
def test_Block_3_check_diagonals_count_2_Player1():
    block = Block_3_In_Line_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', '1', '2', ' ', ' '],
                    [' ', '2', ' ', '1', '2', ' ', ' ']]
    best_move = block._check_diagonals_count(board, 4, 3, '1', 2, True)
    assert (best_move == True)
Exemplo n.º 9
0
def test_Block_3_check_verticals_count_Player1_2():
    block = Block_3_In_Line_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', '1', ' ', ' ', ' ', ' '],
                    [' ', ' ', '2', ' ', ' ', ' ', '2'],
                    [' ', ' ', '2', ' ', '1', '1', '1'],
                    ['2', '1', '2', '2', '2', '1', '1']]
    best_move = block.check_verticals_count(board, 4, 4, '1', 2)
    assert (best_move == True)
Exemplo n.º 10
0
def test_check_diagonals_player1_win_invese_diagonal():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', '1', ' ', ' ', ' ', ' '],
                    ['2', '2', '1', '1', ' ', ' ', ' '],
                    ['2', '1', '2', '1', ' ', ' ', ' '],
                    ['1', '2', '1', '2', ' ', ' ', ' ']]
    fout_in_a_row = checker.check_diagonals(board, 0, '2')
    assert (fout_in_a_row == True)
Exemplo n.º 11
0
def test_check_diagonals_3_in_line_player2():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', '2', '1', ' ', ' ', ' ', ' '],
                    [' ', '1', '2', ' ', ' ', ' ', ' '],
                    ['1', '2', '1', '2', ' ', ' ', ' ']]
    fout_in_a_row = checker.check_diagonals(board, 0, '2')
    assert (fout_in_a_row == False)
Exemplo n.º 12
0
def test__check_horizontals_6_discs_but_an_oponent_disc_in_the_middle():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', '2', '2', '2', ' ', '2'],
                    ['1', '1', '1', '2', '1', '1', '1']]
    discs_in_a_row = checker._check_horizontals(board, 0 + 1, 5, '1', True)
    assert (discs_in_a_row == 2)
Exemplo n.º 13
0
def test__check_horizontals_6_discs_but_only_4_at_the_left():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', '2', '2', '2', ' ', '2'],
                    ['2', '1', '1', '1', '1', '1', '1']]
    discs_in_a_row = checker._check_horizontals(board, 5 - 1, 5, '1', False)
    assert (discs_in_a_row == 4)
Exemplo n.º 14
0
def test__check_horizontals_6_discs_but_only_1_at_the_right():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', '2', '2', '2', ' ', '2'],
                    ['2', '1', '1', '1', '1', '1', '1']]
    discs_in_a_row = checker._check_horizontals(board, 5 + 1, 5, '1', True)
    assert (discs_in_a_row == 1)
Exemplo n.º 15
0
def test_horizontals_win_Player1_row_0_all_3_discs_at_the_right():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', '2', '2', ' ', ' ', ' '],
                    [' ', '1', '1', '1', '1', '2', ' ']]
    four_in_a_row = checker.check_horizontals(board, 1, '1')
    assert (four_in_a_row == True)
Exemplo n.º 16
0
def test_Secuential_Count_check_verticals():
    checker = Secuential_Count_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', '1', ' ', ' ', ' ', ' '],
                    ['2', ' ', '2', '1', ' ', ' ', ' '],
                    ['2', '2', '1', '2', ' ', ' ', ' '],
                    ['2', '1', '1', '1', ' ', '1', '1']]
    neighbour_discs = checker.check_verticals_count(board, 1, 0, '2', 4)
    assert (neighbour_discs == 1)
Exemplo n.º 17
0
def test_Secuential_Count_check_diagonals():
    checker = Secuential_Count_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', '1', ' ', ' ', ' ', ' '],
                    ['2', ' ', '2', '1', ' ', ' ', ' '],
                    ['2', '2', '1', '2', ' ', ' ', ' '],
                    ['2', '1', '1', '1', ' ', '1', '1']]
    neighbour_discs = checker.check_diagonals(board, 3, 2, '2', 3)
    assert (neighbour_discs == 1)
Exemplo n.º 18
0
def test__check_diagonals_player2_5_in_diagonal_but_not_next_pos_6_5():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', '2', ' ', ' ', ' ', ' ', ' '],
                    ['1', '1', '2', ' ', ' ', ' ', ' '],
                    ['1', '1', '1', '2', ' ', ' ', ' '],
                    ['2', '1', '2', '1', '2', ' ', ' '],
                    ['2', '2', '2', '1', '2', '1', ' '],
                    ['1', '2', '1', '2', '1', '1', '2']]
    diagonal_discs = checker._check_diagonals(board, 6 - 1, 5 - 1, '2', True)
    assert (diagonal_discs == 0)
Exemplo n.º 19
0
def test_Check_check_lines_3_in_line_count_3():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', '2', ' ', ' ', ' '],
                    [' ', '1', ' ', '1', ' ', ' ', ' '],
                    [' ', '2', ' ', '2', ' ', ' ', ' '],
                    ['2', '1', ' ', '1', ' ', ' ', ' ']]
    neighbour_discs = checker.check_lines(board, '2', 3)
    assert (neighbour_discs == 3)
Exemplo n.º 20
0
def test__check_diagonals_player2_4_in_diagonal_just_1_down_pos_3_2():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', '2', ' ', ' ', ' ', ' ', ' '],
                    ['1', '1', '2', ' ', ' ', ' ', ' '],
                    ['1', '1', '1', '2', ' ', ' ', ' '],
                    ['2', '1', '2', '1', '2', ' ', ' '],
                    ['2', '2', '2', '1', '2', '1', ' '],
                    ['1', '2', '1', '2', '1', '1', '2']]
    diagonal_discs = checker._check_diagonals(board, 3 + 1, 2 + 1, '2', False)
    assert (diagonal_discs == 1)
Exemplo n.º 21
0
def test_Block_3_check_horizontals_count_3_Player1():
    block = Block_3_In_Line_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', '2', ' ', '1', '2', ' ', ' ']]
    best_move = block.check_horizontals_count(board, 5, 3, '1', 3)
    assert (best_move == True)
Exemplo n.º 22
0
def test__check_diagonals_player2_4_in_diagonal_just_2_up_pos_3_2():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', '2', ' ', ' ', ' ', ' ', ' '],
                    ['1', '1', '2', ' ', ' ', ' ', ' '],
                    ['1', '1', '1', '2', ' ', ' ', ' '],
                    ['2', '1', '2', '1', '2', ' ', ' '],
                    ['2', '2', '2', '1', '2', '1', ' '],
                    ['1', '2', '1', '2', '1', '1', '2']]
    diagonal_discs = checker._check_diagonals(board, 3 - 1, 2 - 1, '2', True)
    assert (diagonal_discs == 2)
Exemplo n.º 23
0
def test_Block_3_check_diagonals_count_3_Player1_only_2_inside_limit():
    block = Block_3_In_Line_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['1', '1', ' ', ' ', ' ', ' ', ' '],
                    ['2', '1', ' ', '1', '2', ' ', ' '],
                    ['1', '2', '1', '1', '2', ' ', ' ']]
    best_move = block._check_diagonals_count(board, 4, 3, '1', 3, True)
    assert (best_move == False)
Exemplo n.º 24
0
def test_check_horizontals_count_1_with_0_neighbours():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', '1', ' ', ' ', ' ']]
    neighbour_discs = checker.check_horizontals_count(board, 5, 3, '1', 0)
    assert (neighbour_discs == 1)
Exemplo n.º 25
0
def test_minimax_Play_3_in_line():
    secuential = Block_3_In_Line(1, '1', '2')
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', '2', ' ', ' '],
                    [' ', '1', '1', '1', '2', ' ', ' ']]
    best_move = secuential.heuristic(board)
    assert (best_move == 1200)
Exemplo n.º 26
0
def test_check_horizontals_count_0_with_2_neighbours_but_search_limit_2():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', '2', ' ', ' ', '2'],
                    ['1', ' ', ' ', '1', ' ', ' ', '1']]
    neighbour_discs = checker.check_horizontals_count(board, 5, 3, '1', 2)
    assert (neighbour_discs == 0)
Exemplo n.º 27
0
def test_minimax_Block3_in_line():
    block_3 = Block_3_In_Line(1, '2', '1')
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', '2', '2', '1', ' ']]
    best_move = block_3.heuristic(board)
    assert (best_move == 1100)
Exemplo n.º 28
0
def test_check_diagonals_count_2_with_2_neighbours_search_limit_1_Player2():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', '2', ' ', ' ', ' '],
                    [' ', ' ', '2', '1', ' ', ' ', ' '],
                    [' ', ' ', '1', '2', ' ', ' ', '2'],
                    ['2', '1', '1', '1', ' ', ' ', '1']]
    neighbour_discs = checker.check_diagonals_count(board, 5, 0, '2', 1)
    assert (neighbour_discs == 2)
Exemplo n.º 29
0
def test_check_verticals_count_5_limit_99():
    checker = Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', ' ', ' ', ' ', ' ', ' '],
                    ['2', ' ', '1', ' ', ' ', ' ', ' '],
                    ['2', ' ', '2', '1', ' ', ' ', ' '],
                    ['2', '2', '1', '2', ' ', ' ', ' '],
                    ['2', '1', '1', '1', ' ', '1', '1']]
    neighbour_discs = checker.check_verticals_count(board, 1, 0, '2', 4)
    assert (neighbour_discs == 1)
Exemplo n.º 30
0
def test_Secuential_Count_check_lines_3_in_line_count_4():
    checker = Secuential_Count_Checker()
    board = Board(6, 7)
    board.matrix = [[' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', ' '],
                    [' ', ' ', ' ', ' ', ' ', ' ', '2'],
                    [' ', ' ', ' ', ' ', ' ', ' ', '1'],
                    [' ', ' ', '2', ' ', ' ', '1', '1'],
                    ['2', '1', '2', '2', '2', '1', '1']]
    neighbour_discs = checker.check_lines(board, '1', 2)
    assert (neighbour_discs == 14)
Exemplo n.º 31
0
def shortestPath():
	B = Board()

	p1 = Pawn()
	p2 = Pawn()

	B.set_value( (6, 6), p1)
	B.set_value( (7, 7), p2)

	B.shortestPath( (5,5), (8, 8))
	B.shortestPath( (1,1), (1,3))
Exemplo n.º 32
0
def convertBoard(fileName, outFileName):
    logging.info("*******************************************")
    logging.info("Converting: " + fileName)
    logging.info("Outputing: " + outFileName + "\n")

    try:

        node = getRootNode(fileName)
        brd = Board(node)
        open(outFileName, 'w').close()
        outFile = open(outFileName, "a")
        brd.write(outFile)
        outFile.close()

    except BaseException as e:
        logging.error("Conversion Failed")
        logging.error(traceback.format_exc())
        logging.info("*******************************************\n\n")
        return False, "Error Converting Board \n" + str(e) + "\nSee Log.txt for more info"

    logging.info("Conversion Successfull")
    logging.info("*******************************************\n\n")
    return True, "The Board Has Finished Converting"
Exemplo n.º 33
0
	def __init__(self):
		self.board = Board()
		self.players = []
		self.currentPlayer = None
		self.cardDeck = CardDeck()

		self.defender = None
		self.superFighterCard = None

		self.lastDice = 0

		pygame.init()

		diceImages = {}

		for n in range(1, 7):
			diceImages[n] = pygame.image.load("Tiles/Roll{}.png".format(n))

		self.images = {
			'rules': pygame.image.load("images/regels v2.5.png".format(n)),
			'dice': diceImages,
			'background': pygame.image.load("Tiles/background.png"),
			'introbackground': pygame.image.load('images/survivorstockimage.png'),
			'box_glove': pygame.image.load('images/Lboximg.png'),
			'boxwinner': pygame.image.load('images/boxwinner.png'),
			'boxpvp': pygame.image.load('images/PVPimg.png'),
			'laurel': pygame.image.load('images/laurel.png'),
			'points': {
				PlayerType.Red: pygame.image.load('Tiles/Lifepoints.png'),
				PlayerType.Blue: pygame.image.load('Tiles/LifepointsBlue.png'),
				PlayerType.Green: pygame.image.load('Tiles/LifepointsGreen.png'),
				PlayerType.Yellow: pygame.image.load('Tiles/LifepointsYellow.png'),
			},
			'conditionPoints': pygame.image.load('Tiles/Conditionpoints.png'),
			'superfightercard': pygame.image.load('images/SuperFighterCard.png'),
		}
Exemplo n.º 34
0
class SurvivorGame:
	def __init__(self):
		self.board = Board()
		self.players = []
		self.currentPlayer = None
		self.cardDeck = CardDeck()

		self.defender = None
		self.superFighterCard = None

		self.lastDice = 0

		pygame.init()

		diceImages = {}

		for n in range(1, 7):
			diceImages[n] = pygame.image.load("Tiles/Roll{}.png".format(n))

		self.images = {
			'rules': pygame.image.load("images/regels v2.5.png".format(n)),
			'dice': diceImages,
			'background': pygame.image.load("Tiles/background.png"),
			'introbackground': pygame.image.load('images/survivorstockimage.png'),
			'box_glove': pygame.image.load('images/Lboximg.png'),
			'boxwinner': pygame.image.load('images/boxwinner.png'),
			'boxpvp': pygame.image.load('images/PVPimg.png'),
			'laurel': pygame.image.load('images/laurel.png'),
			'points': {
				PlayerType.Red: pygame.image.load('Tiles/Lifepoints.png'),
				PlayerType.Blue: pygame.image.load('Tiles/LifepointsBlue.png'),
				PlayerType.Green: pygame.image.load('Tiles/LifepointsGreen.png'),
				PlayerType.Yellow: pygame.image.load('Tiles/LifepointsYellow.png'),
			},
			'conditionPoints': pygame.image.load('Tiles/Conditionpoints.png'),
			'superfightercard': pygame.image.load('images/SuperFighterCard.png'),
		}

	def Reset(self, numberOfPlayers):
		self.board = Board()
		self.__setPlayers(numberOfPlayers)

	def __setPlayers(self, numberOfPlayers):
		players = []

		self.players = players

		self.currentPlayer = 0

		if numberOfPlayers == 2:
			players.append(Players.MikeTysen)
			players.append(Players.BadrHerl)

		elif numberOfPlayers == 3:
			players.append(Players.MikeTysen)
			players.append(Players.RockyBelboa)
			players.append(Players.BadrHerl)

		elif numberOfPlayers == 4:
			players.append(Players.MikeTysen)
			players.append(Players.RockyBelboa)
			players.append(Players.BadrHerl)
			players.append(Players.MannyPecquiao)

		for player in players:
			self.board.placePlayer(player)

	def CurrentPlayer(self):
		self.currentPlayer %= len(self.players)

		return self.players[self.currentPlayer]

	def MoveCurrentPlayer(self, n):

		player = self.CurrentPlayer()
		# player.moveTimes(n)
		fightType = self.MovePlayer(player, n)

		return fightType

	def NextPlayer(self):
		self.currentPlayer += 1
		self.currentPlayer %= len(self.players)

	def IsPlayerIsInGame(self, playerType):
		return len([player for player in self.players if player.playerType == playerType]) == 1

	# move this player n times on the board
	def MovePlayer(self, player, n):
		fightType = FightType.NoFight
		movesound = pygame.mixer.Sound("Sounds/MoveSound.ogg")
		pygame.mixer.Sound.play(movesound)

		# if player is not placed on board then display message
		if player.tile is None:
			return

		initiallyAtOwnCorner = player.isAtOwnCorner()
		passedThroughOwnCorner = False

		# will move n times
		for i in range(1, n + 1):
			# remove this player from old tile
			player.tile.players.remove(player)

			# move this player to new tile
			player.tile = player.tile.nextTile

			# add this player to the players list o new tile
			player.tile.players.append(player)

			if player.isAtOwnCorner():
				passedThroughOwnCorner = True

		# if new tile is FIGHT, then has to fight with super fighter
		if player.isAtOwnCorner():
			OwnCornerBell = pygame.mixer.Sound("Sounds/OwnCornerBell.ogg")
			pygame.mixer.Sound.play(OwnCornerBell)
			player.health += 10

		elif not initiallyAtOwnCorner and passedThroughOwnCorner:
			print("passed from own corner, increasing health/stamina")

			player.stamina = 15

		if player.health > 100:
			player.health = 100

		if player.stamina > 15:
			player.stamina = 15

		# get the list of other players at new location
		others = player.otherPlayers()

		# if there are other players in new position
		if player.tile.tileType == TileType.Fight:
			fightType = FightType.SuperFighter
		elif len(others) > 0:
			# if there are more than 1 player, then player has to choose
			# which t fight with
			if len(others) > 1:
				fightType = FightType.ChoosePlayer
			# print("FIGHT! there are more players here, choose one of : " + ", ".join(
			#	[str(player.playerType) for player in others]))
			# there is one player at new position
			else:
				fightType = FightType.Player
			# if new position is other player's corner then player has to fight with owner
		elif player.isAtOtherPlayersCorner():
			if self.IsPlayerIsInGame(player.tile.cornerOfPlayer):
				pass
			else:
				fightType = FightType.NoFight
				player.health -= 10

		return fightType

	def PickSuperFighterCard(self):
		return self.cardDeck.pickCard()

	def DecreasePlayerHealth(self, player, n):
		player.health -= n

		if player.health <= 0:
			player.health = 0

			self.RemovePlayerFromGame(player)

	def RemovePlayerFromGame(self, player):
		self.players = [p for p in self.players if p is not player]

		if player.tile is not None and player in player.tile.players:
			player.tile.players.remove(player)
Exemplo n.º 35
0
	def Reset(self, numberOfPlayers):
		self.board = Board()
		self.__setPlayers(numberOfPlayers)
Exemplo n.º 36
0
import cProfile
import pstats

from Board.Board import Board, FakeIdleManager
from Board.IdleTasks.ShorelineComputer import ShorelineComputer
from Board.IdleTasks.SecurityComputer import SecurityComputer
from Board.IdleTasks.ServiceComputer import ServiceComputer
from Board.IdleTasks.SurfaceNeedsChecker import SurfaceNeedsChecker
from Board.GameItemTypes import GameItemTypes
GameItemTypes = GameItemTypes.Instance()

b = Board( FakeIdleManager() )
b.load( "examples/Syracusae.c4plan" )
polygon = GameItemTypes.CreatePolygon( "SmallInsula", 0, 0, 0 )

shorelineComputer = ShorelineComputer( b )
securityComputer = SecurityComputer( b )
serviceComputer = ServiceComputer( b, "Religion.Jupiter" )
surfaceNeedsChecker = SurfaceNeedsChecker( b )

class MyIdleManager():
    def add( self, name, function, *args ):
        function( *args )

idleManager = MyIdleManager()

def test():
    for i in range( 2 ):
        shorelineComputer.surfaceChange( "Water", idleManager )
        securityComputer.surfaceChange( "Wall", idleManager )
        serviceComputer.surfaceChange( "Road", idleManager )
Exemplo n.º 37
0
from Board.Enumerations import *
from Board.Board import Board
from Board.Player import Player

# create a new board, will have tiles already setup
board = Board()

# create players
redPlayer = Player(PlayerType.Red)
bluePlayer = Player(PlayerType.Blue)
yellowPlayer = Player(PlayerType.Yellow)
greenPlayer = Player(PlayerType.Green)

# place players on board
board.placePlayer(redPlayer, 0, 0)
board.placePlayer(bluePlayer, 0, 6)
board.placePlayer(yellowPlayer, 0, 6)
board.placePlayer(greenPlayer, 0, 8)

# will move red player from 0, 0 to 0, 5. This location is FIGHT tile
redPlayer.moveTimes(5)

# will move red player from 0, 5 to 0, 6. blue and yellow players are at this location, FIGHT
# red player has to choose which to fight with
redPlayer.moveTimes(1)

# will move red player from 0, 6 to 0, 8. green player is at this location, FIGHT
redPlayer.moveTimes(2)

# will move red player from 0, 8 to 1, 10. this is blue player's corner, FIGHT
redPlayer.moveTimes(3)