generated from CogitoNTNU/README-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from src.agents.agent_factory import create_agent | ||
from src.game.tetris import Tetris | ||
from src.game.TetrisGameManager import * | ||
|
||
if __name__ == "__main__": | ||
board = Tetris() | ||
agent = create_agent("heuristic") | ||
manager = TetrisGameManager(board) | ||
manager.startDemo(agent) |
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
import argparse | ||
from src.game.tetris import Tetris | ||
from src.game.TetrisGameManager import * | ||
from src.agents.agent import Agent, play_game | ||
from src.game.TetrisGameManager import TetrisGameManager | ||
from src.agents.agent_factory import create_agent | ||
from src.agents.heuristic import ( | ||
utility | ||
) | ||
from src.agents.heuristic_trainer import train | ||
from src.agents.geneticAlgAgentJon import GeneticAlgAgentJM | ||
|
||
def test(): | ||
# algAgent = GeneticAlgAgentJM() | ||
# algAgent.number_of_selection(2) | ||
# print(algAgent.getBestPop()) | ||
|
||
def self_play(): | ||
"""Start a self-playing Tetris game.""" | ||
board = Tetris() | ||
agent = create_agent("heuristic") | ||
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() | ||
elif args.command == "agent": | ||
demonstrate(args.agent) | ||
elif args.command == "train": | ||
train_genetic_algorithm(args.population_size) | ||
else: | ||
parser.print_help() | ||
if __name__ == "__main__": | ||
|
||
# game = Tetris() | ||
# agent: Agent = create_agent("heuristic") | ||
# sum_rows_removed = 0 | ||
# for i in range(10): | ||
# end_board = play_game(agent, game, 7) | ||
# end_board.printBoard() | ||
# sum_rows_removed += end_board.rowsRemoved | ||
|
||
# print(f"Average rows removed: {sum_rows_removed / 10}") | ||
|
||
# possible_moves = game.getPossibleBoards() | ||
# for boards in possible_moves: | ||
# print(utility(boards, 0, -1, 0, 0, 0)) | ||
# boards.printBoard() | ||
|
||
# board = Tetris() | ||
# manager = TetrisGameManager(board) | ||
# agent = create_agent("heuristic") | ||
|
||
# # manager.startGame() | ||
|
||
# # train() | ||
|
||
|
||
# algAgent = GeneticAlgAgentJM() | ||
# algAgent.number_of_selection(2) | ||
# print(algAgent.getBestPop()) | ||
|
||
test() | ||
|
||
|
||
# cProfile.run('main()', 'restats') | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
colorama==0.4.6 | ||
iniconfig==2.0.0 | ||
numpy==1.26.4 | ||
packaging==24.0 | ||
pluggy==1.4.0 | ||
pluggy==1.5.0 | ||
pygame==2.5.2 | ||
pynput==1.7.6 | ||
pytest==8.1.1 | ||
six==1.16.0 | ||
pytest==8.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
from src.game.block import Block | ||
|
||
DEMO_SLEEP = 0.05 | ||
DEMO_SLEEP = 0 | ||
|
||
|
||
class Action(Enum): | ||
|