示例#1
0
def make_move(board, color, roll):
    print("Called with: ", color, roll)
    field = board.get_board()
    max_eval, move = -100000000, 0
    if field[color][0] > 0:
        # print("Hit Case")
        if field[OTHER[color]][25 - roll] <= 1:
            board.move_checker(color, 0, roll)
            return board
    elif board.takeout[color]:
        # print("Takeout Case")
        if field[color][25 - roll] > 0:
            board.move_checker(color, 25 - roll, roll)
            return board
        else:
            for i in range(19, 25 - roll):
                if field[color][i] > 0:
                    board.move_checker(color, i, roll)
                    return board
            for i in range(25 - roll, 25):
                if field[color][i] > 0:
                    board.move_checker(color, i, roll)
                    return board
    else:
        # print("Default Case")
        new_board = copy.deepcopy(board)
        for i in range(24, 0, -1):
            if 0 < i - roll < 25 and field[color][i - roll] > 0:
                if new_board.move_checker(color, i - roll, roll):
                    # new_board.print_board()
                    if value(new_board, color) >= max_eval:
                        max_eval = value(new_board, color)
                        move = i
                # print(i)
                # board.print_board()
                # print(value(board, color), max_eval)
                new_board = copy.deepcopy(board)
                # board.print_board()
        # print("Got to here")
        # print(move)
        # board.print_board()
        board.move_checker(color, move - roll, roll)
        return board
示例#2
0
def main():
    board = Board()
    dice = board.throw_dice()
    color = "B"
    line = ""
    board.print_board()
    try:
        while True:
            if color == "B":
                dice = board.throw_dice()
                print("DICE: ", dice)
                i = 0
                while i < len(dice):
                    line = input("What to move " + str(dice[i]) + " places? (0 to switch dice)")
                    if int(line) == 0:
                        tmp = dice[0]
                        for i in range(len(dice) - 1):
                            dice[i] = dice[i + 1]
                        dice[len(dice) - 1] = tmp
                        continue
                    elif line == "exit":
                        return
                    pos = int(line)
                    if board.move_checker(color, pos, dice[i]):
                        i += 1
                    else:
                        print("Cannot move this, try again!")
                    board.print_board()
                color = OTHER[color]
            else:
                dice = board.throw_dice()
                print("DICE: ", dice)
                try:
                    if len(dice) == 2:
                        try:
                            board = copy.deepcopy(play(board, color, dice))
                        except:
                            board = copy.deepcopy(play(board, color, [dice[1], dice[0]]))
                        # print("Max: \n", play(board, color, dice).print_board())
                    elif len(dice) == 4:
                        board = copy.deepcopy(play(board, color, [dice[0], dice[1]]))
                        board = copy.deepcopy(play(board, color, [dice[2], dice[3]]))
                    board.print_board()
                    color = OTHER[color]
                except:
                    color = OTHER[color]
    except:
        print("End of game")
示例#3
0
				wrong_label_pos_x, wrong_label_pos_y = pygame.mouse.get_pos()[0] - 100, pygame.mouse.get_pos()[1]
				wrong_label = myfont.render("Pick a blue checker", 1, (255, 125, 50))
				label_time = 20
				trigger_wrong_label = True


		if event.type == MOUSEBUTTONUP:
			if pygame.mouse.get_pos()[0] < board.get_board_width():
				next_coordinates = board.get_next_row_coordinates(coordinates_array, space_value, first_row_index, first_space_index)
				second_row_index, second_space_index = board.get_checker_index(coordinates_array, pygame.mouse.get_pos())
				release_space_value = board.get_space_value(second_row_index, second_space_index)
				release_pos = board.get_space_coordinates(coordinates_array, second_row_index, second_space_index)
				print "release " + str(release_pos)
				if release_pos in next_pos and release_space_value == 1:
					current_player_array[current_index].new_pos(release_pos)
					board.move_checker(coordinates_array, pygame.mouse.get_pos(), release_space_value, space_value, first_row_index, first_space_index)
					
					## Coronar ficha
					if release_pos[1] == 504 and current_turn == [2, 4]:
						current_player_array[current_index].checker_sprite = sprites_dict["top_player"]["king"]
						current_player_array[current_index].checker_sprite_alpha = sprites_dict["top_player"]["king_alpha"]
						board_array[second_row_index][second_space_index] = 4
					else:
						if release_pos[1] == 63 and current_turn == [3, 5]:
							current_player_array[current_index].checker_sprite = sprites_dict["bottom_player"]["king"]
							current_player_array[current_index].checker_sprite_alpha = sprites_dict["bottom_player"]["king_alpha"]
							board_array[second_row_index][second_space_index] = 5


					## Revisar si hay fichas que se puedan comer
					if release_pos not in next_coordinates and release_pos[1] not in (63, 504):