def solve(): sets=[] with open("ProblemList.txt") as r: for line in r: line = line.rstrip() problem = Problem(line, '2x2') sets.append(problem) agent = Agent() for problem in sets: agent.Solve(problem)
def add_agents(self, nb): old_length = len(self.agents) for index in range(old_length, old_length + nb): self.agents.append( Agent(id_=index, prediction_queue=self.prediction_queue, training_queue=self.training_queue, states=self.train_set, exit_flag=Value(c_bool, False), statistics_queue=self.statistics_queue, episode_counter=self.nb_episodes, observation_shape=(self.channels, self.height, self.width), action_space=self.n_outputs, device=self.agent_device, step_max=self.sequence_length))
def OnNewGame(self, event): """Creates a new game.""" playerTokenAnswer = self.PromptForToken( ) # Prompts user for his choice of token X or O. if playerTokenAnswer == wx.ID_CANCEL: # Do nothing if user cancelled the NewGame.. return if not hasattr(self, 'board'): self.board = TicTacToe() self.agent = Agent() self.mainGrid = TTTPanel(self) self.Layout() else: self.ClearMainGrid() self.board.clear() self.over = False if playerTokenAnswer == wx.ID_YES: # Player chose 'X'. self.agent.token = 'O' self.SetStatusText("X to start!") else: # Player chose 'O'. self.agent.token = 'X' self.SetStatusText("Computer is thinking...") self.AgentMove() self.SetStatusText("O to move!")
parser = argparse.ArgumentParser() parser.add_argument('-s', dest='size', type=int) parser.add_argument('-b', dest='blanks', action='store_true') parser.add_argument('-e', dest='expectimax', action='store_true') parser.add_argument('-p', dest='prune', action='store_true') results = parser.parse_args() if not results.size: results.size = 15 rules = ScrabbleRules(blanks=results.blanks, size=results.size) state = GameState(blanks=results.blanks, size=results.size) view = View() agent_0 = Agent() agent_1 = Agent() state.add_agent(0, agent_0) state.add_agent(1, agent_1) state.place('A', [(results.size // 2, results.size // 2)], 0, rules) state.draw(0) state.draw(1) # Play agents = [0, 1] try: while True: for agent in agents: state.draw(agent) best_move = None if results.expectimax:
from src.Agent import Agent from src.TicTacToe import TicTacToe board1 = ['X', 'X', ' ', 'O', 'O', ' ', ' ', ' ', ' '] drawn_board = ['X', 'X', 'O', 'O', 'O', 'X', 'X', 'X', 'O'] board_O = ['X', 'X', 'O', 'X', 'O', ' ', 'O', ' ', ' '] O_to_win = ['X', 'X', 'O', 'X', 'O', ' ', ' ', ' ', ' '] newgame = TicTacToe() game1 = TicTacToe(board1) drawn_game = TicTacToe(drawn_board) game_o = TicTacToe(board_O) game_o_to_win = TicTacToe(O_to_win) agentx = Agent() agento = Agent(token='O') def test_eval_game_over(): assert agentx.eval_game_over(drawn_game) == 0 assert agentx.eval_game_over(game_o) == -10 assert agento.eval_game_over(game_o) == 10 def test_eval(): assert agentx.eval(game1) == 9 assert agento.eval(game1) == -9 def test_choose_move(): assert agentx.choose_move(game1) == 2
import argparse import time import sys sys.path.insert(0, 'src') from src.Agent import Agent if __name__ == '__main__': ap = argparse.ArgumentParser() ap.add_argument('-b', '--behaviour', type=str, required=True, help='behaviour name') ap.add_argument('-m', '--minutes', type=int, required=True, help='activate behaviour on X minutes') ap.add_argument('-d', '--delay', type=int, default=5, help='delay in seconds') args = vars(ap.parse_args()) time.sleep(args['delay']) agent = Agent() agent.AddBehaviour(args['behaviour'], args['minutes']) agent.Activate()
parser = argparse.ArgumentParser() parser.add_argument( "-m", "--mode", default=available_modes[0], choices=available_modes, dest="mode", help= """Running mode of AI ["TACTICS", "MATCHES", "TEST_TACTICS", "TEST_MATCHES"]""" ) parser.add_argument("-a", "-ai", default="TestModel", choices=list(available_networks.keys()), dest="ai_model", help="""Select AI Models""") parser.add_argument("-e", "--epochs", default=1, type=int, dest="epochs", help="""Count of Epochs""") args = parser.parse_args() agent = Agent(ai_name=args.ai_model, mode=args.mode, epochs=args.epochs, players=ConstantGame.count_teams()) agent.run()