-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCTSPacmanAgent_MCTSPacmanAgent2.py
54 lines (43 loc) · 1.51 KB
/
MCTSPacmanAgent_MCTSPacmanAgent2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from captureAgents import CaptureAgent
import random, time, util
from game import Directions
import game
from capture import GameState
from util import nearestPoint
from mcts import Node
from mcts import MCTSAgent
#################
# Team creation #
#################
def createTeam(firstIndex, secondIndex, isRed,
first = 'MCTSPacmanAgent1', second = 'MCTSPacmanAgent2'):
return [eval(first)(firstIndex), eval(second)(secondIndex)]
##########
# Agents #
##########
class MCTSPacmanAgent1(MCTSAgent):
"""
A Pacman agent that uses Monte Carlo Tree Search (MCTS) to make decisions.
"""
def registerInitialState(self, gameState):
CaptureAgent.registerInitialState(self, gameState)
def chooseAction(self, gameState):
"""
Choose an action using MCTS.
"""
gameState = GameState.deepCopy(self=gameState)
best_action = MCTSAgent.chooseAction(self, gameState, offensive=True)
return best_action
class MCTSPacmanAgent2(MCTSAgent):
"""
A Pacman agent that uses Monte Carlo Tree Search (MCTS) to make decisions.
"""
def registerInitialState(self, gameState):
CaptureAgent.registerInitialState(self, gameState)
def chooseAction(self, gameState):
"""
Choose an action using MCTS.
"""
gameState = GameState.deepCopy(self=gameState)
best_action = MCTSAgent.chooseAction(self, gameState, offensive=False)
return best_action