def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.core.board.Board.__init__() method', 0) g = None try: g = ChessGame() except Exception as e: log_msg('ChessGame instantiation test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0) return g
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.ai.tree.generate.spawn_tree()', 0) tree = None try: g = ChessGame() tree = spawn_tree(g.board) except Exception as e: log_msg('Phanotm.ai.tree.generate.spawn_tree() test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0) return tree
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.core.board.Board.move() method', 0) b = Board() # white to move, opening layout try: b.move('e2e4') b.move('g8f6') b.move('g2g3') except Exception as e: log_msg('Phantom.core.board.Board.move() method test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0)
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.core.board.Board.move() method', 0) #b = Board(None) # white to move, opening layout b = ChessGame().board try: b.move('e2e4') b.move('g8f6') b.move('g2g3') except Exception as e: log_msg('Phantom.core.board.Board.move() method test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0)
def main(*args): clear_log() log_msg('Phantom beginning self-test', 0, mark=True) testdir = inspect.getfile(main) testdir, dirname = os.path.split(testdir) for f in os.listdir(testdir): if f in (dirname, '__init__.py'): continue else: mn = f[:f.index('.')] m = __import__(mn) m.main(False) log_msg('Phantom self-test complete', 0, mark=True)
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.ai.pos_eval.advanced.pos_eval_advanced()', 0) for test in list_tests(): log_msg('Beginning pos eval on test {}'.format(test), 0) board = load_test(test) score = None try: score = pos_eval_advanced(board) except Exception as e: log_msg('Advanced position evaluation failed: \n{}'.format(e), 0, err=True) finally: log_msg('Pos eval test on {} complete: score={}'.format(test, score), 0) log_msg('Test complete', 0)
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.ai.tree.generate.spawn_tree()', 0) tree = None try: g = ChessGame() tree = spawn_tree(g.board) except Exception as e: log_msg( 'Phantom.ai.tree.generate.spawn_tree() test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0) return tree
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.ai.pos_eval.basic pos_eval_basic() & pos_material()', 0) game = ChessGame() score = material = None try: score = pos_eval_basic(game.board) except Exception as e: log_msg('AI basic position evaluation failed: \n{}'.format(e), 0, err=True) try: material = pos_material(game.board) except Exception as e: log_msg('AI material assesment failed: \n{}'.format(e), 0, err=True) log_msg('Test complete', 0) return score, material
def main(clear=True): print('=' * 50) from Phantom.core.game_class import ChessGame from Phantom.utils.debug import log_msg, clear_log if clear: clear_log() log_msg('Testing Phantom.ai.tree.generate.spawn_tree()', 0) tree = None try: g = ChessGame() tree = spawn_tree(g.board) except ImportError: #Exception as e: log_msg('Phantom.ai.tree.generate.spawn_tree() test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0) return tree
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.ai.pos_eval.heuristics functions', 0) g = ChessGame('Game 1') log_msg('Testing AI heuristics on savegame "Game 1":', 0) score = 0 for rule in all_rules: try: log_msg(rule.__name__ + " evaluating...", 0) r = rule(g.board) log_msg(rule.__name__ + ' returned {}'.format(r), 0) score += r except Exception as e: log_msg('{} failed:\n{}'.format(f.__name__, e), 0, err=True) log_msg('Test complete', 0) return score
def main(clear=True): if clear: clear_log() log_msg('Testing Phantom.ai.pos_eval.advanced.pos_eval_advanced()', 0) for test in list_tests(): log_msg('Beginning pos eval on test {}'.format(test), 0) board = load_test(test) score = None try: score = pos_eval_advanced(board) except Exception as e: log_msg('Advanced position evaluation failed: \n{}'.format(e), 0, err=True) finally: log_msg( 'Pos eval test on {} complete: score={}'.format(test, score), 0) log_msg('Test complete', 0)
def main(clear=True): from Phantom.utils.debug import log_msg, clear_log from Phantom.core.game_class import load_game # ChessGame if clear: clear_log() log_msg('Testing Phantom.ai.pos_eval.heuristics functions', 0) g = load_game('Game 1') log_msg('Testing AI heuristics on savegame "Game 1":', 0) score = 0 for rule in all_rules: #try: log_msg(rule.__name__ + " evaluating...", 0) r = rule(g.board) log_msg(rule.__name__ + ' returned {}'.format(r), 0) score += r #except Exception as e: # log_msg('{} failed:\n{}'.format(f.__name__, e), 0, err=True) log_msg('Test complete', 0) return score
def main(clear=True): if clear: clear_log() log_msg( 'Testing Phantom.ai.pos_eval.basic pos_eval_basic() & pos_material()', 0) game = ChessGame() score = material = None try: score = pos_eval_basic(game.board) except Exception as e: log_msg('AI basic position evaluation failed: \n{}'.format(e), 0, err=True) try: material = pos_material(game.board) except Exception as e: log_msg('AI material assesment failed: \n{}'.format(e), 0, err=True) log_msg('Test complete', 0) return score, material
def main(clear=True): print('=' * 50) from Phantom.core.game_class import ChessGame from Phantom.utils.debug import log_msg, clear_log if clear: clear_log() log_msg('Testing Phantom.ai.tree.generate.spawn_tree()', 0) tree = None try: g = ChessGame() tree = spawn_tree(g.board) except ImportError: #Exception as e: log_msg( 'Phantom.ai.tree.generate.spawn_tree() test failed:\n{}'.format(e), 0, err=True) finally: log_msg('Test complete', 0) return tree
def main(clear=True): if clear: clear_log() log_msg('Beginning Phantom.core.boardio load functions test', 0) try: log_msg('Testing FEN load...', 0) name = listgames()[0] game = load(name) except Exception as e: log_msg('Test failed: {}'.format(e), 0, err=True) finally: log_msg('FEN load test complete.', 0) try: log_msg('Testing EPD load...', 0) name = list_tests()[0] game = load_test(name) except Exception as e: log_msg('Test failed: {}'.format(e), 0, err=True) finally: log_msg('EPD load test complete.', 0) log_msg('Phantom.core.boardio load functions test complete.', 0)
def main(clear=True): if clear: clear_log() log_msg('Beginning Phantom.core.boardio load functions test', 0) try: log_msg('Testing FEN load...', 0) name = list_games()[0] game = load(name) except Exception as e: log_msg('Test failed: {}'.format(e), 0, err=True) finally: log_msg('FEN load test complete.', 0) try: log_msg('Testing EPD load...', 0) name = list_tests()[0] game = load_test(name) except Exception as e: log_msg('Test failed: {}'.format(e), 0, err=True) finally: log_msg('EPD load test complete.', 0) log_msg('Phantom.core.boardio load functions test complete.', 0)