示例#1
0
文件: __init__.py 项目: fiedlr/golex
def run(dimensions, turns, terminal=1):
    """ Run a game with the chosen config - accessible through terminal """

    # Run the game
    game = Game(dimensions, turns, terminal)  # debug flag = 1
    strategy1 = Castle(game)
    strategy2 = Ship(game, "~")

    # Opposing strategies
    game.add_strategy(strategy1).add_strategy(strategy2)

    # Choose the board
    print("Welcome to Game of Life Extended (codename golex) v.", game.VERSION)
    print(
        "This game takes GoL to the next level by bringing 2 players (strategies) together and making them fight each other.\n"
    )

    # Start line
    print("Initial configuration with the chosen strategies (", strategy1.SIGN,
          ",", strategy2.SIGN, "):")

    # Set up the initial configuration
    game.build()

    # Make user see what's happening
    if terminal:
        input("Press Enter to continue")

    print("\nProceeding with the simulation...")

    # Iterate through the GoL algorithm
    game.run()

    winner = game.get_winner()

    print("Resulting board:")

    game.print_state()

    print()

    # Show the winner
    print("The winning strategy is '", winner, "'")

    # End line
    print()

    return winner
示例#2
0
文件: stats.py 项目: fiedlr/golex
""" golex v0.7 <github.com/fiedlr/golex> | (c) 2016 Adam Fiedler | <opensource.org/licenses/MIT> """

from main import Game
from strategies import *

# Winner container
winners = []

# Make 100 games
for i in range(100):
	game = Game([10, 20], 100, 0)
	strategies = [Ship(game), Castle(game)]
	# Opposing strategies
	game.add_strategy(strategies[0]).add_strategy(strategies[1])
	# Build
	game.build()
	# Run
	game.run()
	# Winner
	if game.get_winner() != None:
		winners.append(strategies.index(game.get_winner()))
	else:
		winners.append(-1)

print("Ship#1 wins:", winners.count(0), "Castle wins:", winners.count(1), "Draws:", winners.count(-1))
print("Ship chance of winning against castle: ", winners.count(0) / len(winners))