Esempio n. 1
0
def main():
    print("This will play a single game and then quit.")
    print("The minesweeper window needs focus to capture a key press.")
    print()

    # results = ms.run_games(config, num_games, ai)
    results = ms.run_games(config, num_games, ai, threads=MAX_THREADS)
    print('\n\nResults:')
    print('-------------------------')

    num_wins = 0
    for i, result in results:
        num_wins += result.victory == True
        print('Game {:2d}: {:3d} steps, {:s}'.format(
            i, result.num_moves, 'win' if result.victory else 'failed'))

    ratio = num_wins / num_games
    print('-------------------------')
    print('Ratio: {:.2f}'.format(ratio))
Esempio n. 2
0
        self.exposed_squares = set()

    def init(self, config):
        self.width = config.width
        self.height = config.height
        self.exposed_squares.clear()

    def next(self):
        while True:
            x = random.randint(0, self.width - 1)
            y = random.randint(0, self.height - 1)
            if (x, y) not in self.exposed_squares:
                break
        print('selecting point ({0},{1})'.format(x, y))
        return x, y

    def update(self, result):
        for position in result.new_squares:
            self.exposed_squares.add((position.x, position.y))


num_games = 1
config = ms.GameConfig()
ai = RandomAI()
viz = ms.GameVisualizer('key')
results = ms.run_games(config, 1, ai, viz)
if results[0].success:
    print('Success!')
else:
    print('Boom!')
print('Game lasted {0} moves'.format(results[0].num_moves))
Esempio n. 3
0
import logging
import minesweeper as ms

logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")

print("This will play a single game and then quit.")
print("The minesweeper window needs focus to capture a key press.")
print()

num_games = 1
config = ms.GameConfig(16, 16, 32)
ai = ms.CSPAI()
viz = ms.PyGameVisualizer(pause=0.1, next_game_prompt=True)
result = ms.run_games(config, num_games, ai, viz).pop()
print('Game lasted {0} moves'.format(result.num_moves))
Esempio n. 4
0
def test_run_games():
    config = ms.GameConfig()
    ai = ms.RandomAI()
    results = ms.run_games(config, 2, ai)
    assert 2 == len(results)