-
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
Krasto
committed
Jan 21, 2024
1 parent
f91aa7b
commit 0d5dc96
Showing
8 changed files
with
160 additions
and
76 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 |
---|---|---|
@@ -1,82 +1,53 @@ | ||
try: | ||
from _players import MinMaxPlayer, MCTSPlayer, RandomPlayer | ||
from helper import evaluate | ||
from helper import evaluate, Result, gen_plots | ||
from main import Player | ||
except: | ||
from ._players import * | ||
from .helper import evaluate | ||
import pytest | ||
from .main import Player | ||
from .helper import evaluate, Result, gen_plots | ||
from pprint import pprint | ||
import dill, multiprocessing | ||
dill.Pickler.dumps, dill.Pickler.loads = dill.dumps, dill.loads | ||
multiprocessing.reduction.ForkingPickler = dill.Pickler | ||
multiprocessing.reduction.dump = dill.dump | ||
|
||
GAMES = 10 | ||
HIDE_PBAR = True | ||
|
||
@pytest.mark.evaluate | ||
def test_minmax_vs_random(): | ||
minmax = MinMaxPlayer() | ||
minmax2 = MinMaxPlayer() | ||
minmax3 = MinMaxPlayer(3, pruning=2) | ||
mcts_r = MCTSPlayer() | ||
mcts_h = MCTSPlayer(sim_heuristic=True) | ||
|
||
print("\n--- --- ---") | ||
print(f"{minmax.name} VS RandomPlayer") | ||
evaluate(minmax, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
print(f"{minmax.name} Stats:") | ||
pprint(minmax.stats, sort_dicts=False) | ||
|
||
@pytest.mark.evaluate | ||
def test_minmax3_vs_random(): | ||
minmax = MinMaxPlayer(3, pruning=2) | ||
def test_minmax_vs_random() -> Result: | ||
return evaluate(minmax2, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
|
||
print("\n--- --- ---") | ||
print(f"{minmax.name} VS RandomPlayer") | ||
evaluate(minmax, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
print(f"{minmax.name} Stats:") | ||
pprint(minmax.stats, sort_dicts=False) | ||
def test_minmax3_vs_random() -> Result: | ||
return evaluate(minmax3, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
|
||
@pytest.mark.evaluate | ||
def test_mcts_r_vs_random(): | ||
mcts = MCTSPlayer() | ||
def test_mcts_r_vs_random() -> Result: | ||
return evaluate(mcts_r, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
|
||
print("\n--- --- ---") | ||
print(f"{mcts.name} vs RandomPlayer") | ||
evaluate(mcts, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
print(f"{mcts.name} Stats:") | ||
pprint(mcts.stats, sort_dicts=False) | ||
|
||
def test_mcts_h_vs_random() -> Result: | ||
return evaluate(mcts_h, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
|
||
@pytest.mark.evaluate | ||
def test_mcts_h_vs_random(): | ||
mcts = MCTSPlayer(sim_heuristic=True) | ||
|
||
print("\n--- --- ---") | ||
print(f"{mcts.name} vs RandomPlayer") | ||
evaluate(mcts, RandomPlayer(), games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
print(f"{mcts.name} Stats:") | ||
pprint(mcts.stats, sort_dicts=False) | ||
def test_minmax_vs_mcts_random() -> Result: | ||
return evaluate(minmax2, mcts_r, games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
|
||
def test_minmax_vs_mcts_heuristic() -> Result: | ||
return evaluate(minmax2, mcts_h, games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
|
||
@pytest.mark.evaluate | ||
def test_minmax_vs_mcts_random(): | ||
minmax = MinMaxPlayer() | ||
mcts = MCTSPlayer() | ||
print("\n--- --- ---") | ||
print(f"{minmax.name} VS {mcts.name}") | ||
evaluate(minmax, mcts, games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
print(f"{minmax.name} Stats:") | ||
pprint(minmax.stats, sort_dicts=False) | ||
print(f"{mcts.name} Stats:") | ||
pprint(mcts.stats, sort_dicts=False) | ||
|
||
@pytest.mark.evaluate | ||
def test_minmax_vs_mcts_heuristic(): | ||
minmax = MinMaxPlayer() | ||
mcts = MCTSPlayer(sim_heuristic=True) | ||
|
||
print("\n--- --- ---") | ||
print(f"{minmax.name} VS {mcts.name}") | ||
evaluate(minmax, mcts, games=GAMES, display=True, hide_pbar=HIDE_PBAR) | ||
print(f"{minmax.name} Stats:") | ||
pprint(minmax.stats, sort_dicts=False) | ||
print(f"{mcts.name} Stats:") | ||
pprint(mcts.stats, sort_dicts=False) | ||
|
||
def call(it: callable) -> Result: | ||
return it() | ||
|
||
if __name__ == "__main__": | ||
print("Use `python -m pytest ci_quixo/__main__.py -m evaluate -s`") | ||
evals = [test_minmax_vs_random, test_minmax3_vs_random, test_mcts_r_vs_random, test_mcts_h_vs_random, test_minmax_vs_mcts_random, test_minmax_vs_mcts_heuristic] | ||
|
||
with multiprocessing.Pool() as p: | ||
RESULTS = p.map(call, evals[:-2]) | ||
|
||
gen_plots(RESULTS) |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.