Skip to content

Commit

Permalink
choir: moved henrik's experiment into separate folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Prokhorikhin committed Jul 5, 2024
1 parent 5dcdbda commit f19918f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,51 @@
from src.game.TetrisGameManager import TetrisGameManager
from src.agents.agent_factory import create_agent
from src.agents.geneticAlgAgentJon import GeneticAlgAgentJM

def self_play():
"""Start a self-playing Tetris game."""
board = Tetris()
manager = TetrisGameManager(board)
manager.startGame()

def demonstrate(agent_type: str):
"""Demonstrate gameplay with a specified agent."""
board = Tetris()
agent = create_agent(agent_type)
manager = TetrisGameManager(board)
manager.startDemo(agent)

def train_genetic_algorithm(population_size: int = 10):
"""Train the genetic algorithm agent."""
alg_agent = GeneticAlgAgentJM()
alg_agent.number_of_selection(population_size)
print(alg_agent.getBestPop())

def main():
"""Main entry point to handle command-line arguments."""
parser = argparse.ArgumentParser(description="Tetris Game with different options.")
subparsers = parser.add_subparsers(dest="command", help="Sub-command help")

# Self-play parser
subparsers.add_parser("play", help="Start a self-playing Tetris game.")

# Demonstrate parser
demonstrate_parser = subparsers.add_parser(
"agent", help="Demonstrate gameplay with a specific agent."
)
demonstrate_parser.add_argument(
"agent", type=str, help="Agent type for demonstration."
)

# Genetic algorithm training parser
train_parser = subparsers.add_parser("train", help="Train the genetic algorithm agent.")
train_parser.add_argument(
"--population_size", type=int, default=10, help="Population size for the genetic algorithm."
)

# Parse the arguments
args = parser.parse_args()

# Route commands to the appropriate functions
if args.command == "play":
self_play()
Expand All @@ -48,5 +57,6 @@ def main():
train_genetic_algorithm(args.population_size)
else:
parser.print_help()

if __name__ == "__main__":
main()
File renamed without changes.
File renamed without changes.

0 comments on commit f19918f

Please sign in to comment.