Repository navigation
Expand file tree
/
Copy pathclassificationAgents.py
More file actions
75 lines (63 loc) · 2.86 KB
/
Copy pathclassificationAgents.py
File metadata and controls
75 lines (63 loc) · 2.86 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# classificationAgents.py
# -----------------------
# Licensing Information: You are free to use or extend these projects for
# educational purposes provided that (1) you do not distribute or publish
# solutions, (2) you retain this notice, and (3) you provide clear
# attribution to UC Berkeley, including a link to http://ai.berkeley.edu.
#
# Attribution Information: The Pacman AI projects were developed at UC Berkeley.
# The core projects and autograders were primarily created by John DeNero
# (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu).
# Student side autograding was added by Brad Miller, Nick Hay, and
# Pieter Abbeel (pabbeel@cs.berkeley.edu).
# pacmanAgents.py
# ---------------
# Licensing Information: You are free to use or extend these projects for
# educational purposes provided that (1) you do not distribute or publish
# solutions, (2) you retain this notice, and (3) you provide clear
# attribution to UC Berkeley, including a link to
# http://inst.eecs.berkeley.edu/~cs188/pacman/pacman.html
#
# Attribution Information: The Pacman AI projects were developed at UC Berkeley.
# The core projects and autograders were primarily created by John DeNero
# (denero@cs.berkeley.edu) and Dan Klein (klein@cs.berkeley.edu).
# Student side autograding was added by Brad Miller, Nick Hay, and
# Pieter Abbeel (pabbeel@cs.berkeley.edu).
from pacman import Directions
from game import Agent
import random
import game
import util
class DummyOptions:
def __init__(self):
self.data = "pacman"
self.training = 25000
self.test = 100
self.odds = False
self.weights = False
import perceptron_pacman
class ClassifierAgent(Agent):
def __init__(self, trainingData=None, validationData=None, classifierType="perceptron", agentToClone=None, numTraining=3):
from dataClassifier import runClassifier, enhancedFeatureExtractorPacman
legalLabels = ['Stop', 'West', 'East', 'North', 'South']
if(classifierType == "perceptron"):
classifier = perceptron_pacman.PerceptronClassifierPacman(legalLabels,numTraining)
self.classifier = classifier
self.featureFunction = enhancedFeatureExtractorPacman
args = {'featureFunction': self.featureFunction,
'classifier':self.classifier,
'printImage':None,
'trainingData':trainingData,
'validationData':validationData,
'agentToClone': agentToClone,
}
options = DummyOptions()
options.classifier = classifierType
runClassifier(args, options)
def getAction(self, state):
from dataClassifier import runClassifier, enhancedFeatureExtractorPacman
features = self.featureFunction(state)
action = self.classifier.classify([features])[0]
return action
def scoreEvaluation(state):
return state.getScore()