Skip to content

Instantly share code, notes, and snippets.

View KarenWest's full-sized avatar

Karen West KarenWest

View GitHub Profile
Below were my attempts at questions1 and 2 from project2, and given the trouble I had with these, I ran out
of time and never got to questions 3-5. However, in my defense, I did understand these algorithms from a
conceptual level when we did homework3 for AI, and on paper, mostly got these algorithms correct. However,
when I tried to implement them in the pacman game--totally lost as you will see below. Any suggestions or
help would be great! If I cannot work out my issues with project2, well, I'm guessing it makes no sense next
week to attempt project3. No worries if you are unable to help here! ;-)
Specifically in class ReflexAgent(), my evaluationFunction() did not pass. I tried referencing the notes,
the homework3 and previous projects, and still could not get this correct.
=begin
Karen West - April 7th, 2013
HW 1-2: Rock-Paper-Scissors
In a game of rock-paper-scissors (RPS), each player chooses to play Rock (R), Paper (P), or Scissors (S). The rules are: R beats S; S beats P; and P beats R. We will encode a rock-paper-scissors game as a list, where the elements are themselves 2-element lists that encode a player's name and a player's selected move, as shown below:
[ ["Armando", "P"], ["Dave", "S"] ] # Dave would win since S > P
Part A: Write a method rps_game_winner that takes a two-element list and behaves as follows:
-- If the number of players is not equal to 2, raise WrongNumberOfPlayersError.
Question is at bottom!
=begin
Karen West April 7th, 2013 - Homework #1 - Saas1 take2 - Question #5
HW 1-5: Advanced OOP, Metaprogramming, Open Classes and Duck Typing
In lecture, we saw how attr_accessor uses metaprogramming to create getters and setters for object attributes on the fly.
Define a method attr_accessor_with_history that provides the same functionality as attr_accessor but also tracks every value the attribute has ever taken. The following example shows the basic behavior of the new accessor:
Saas1 question 6 questions:
Part A: currency converter -- searched you will see for help - autograder had issues with the solution
Part B: have not yet resubmitted -- but seems to work just fine
Part C: tried to modify my Enumerable but has an issue!
# -*- coding: utf-8 -*-
=begin
Karen West - April 7th, 2013 - homework#1 question#6
HW 1-6: Advanced OOP, Metaprogramming, Open Classes and Duck Typing
Question -- error at bottom here - ruby interpreter error
# -*- coding: utf-8 -*-
=begin
Karen West - Saas1 - homework#1 question #7 - April 7th, 2013
HW 1-7: Iterators, Blocks, Yield
Given two collections (of possibly different lengths), we want to get the Cartesian product of the sequences. A Cartesian product is a sequence that enumerates every possible pair from the two collections, where the pair consists of one element from each collection. For example, the Cartesian product (denoted by ×) of the sequences a = [:a, :b, :c] and b = [4, 5] is:
a × b = [ [:a,4], [:a,5], [:b,4], [:b,5], [:c,4], [:c,5] ]
# -*- coding: utf-8 -*-
=begin
Karen West - April 7th, 2013 - homework#1 question#6
HW 1-6: Advanced OOP, Metaprogramming, Open Classes and Duck Typing
Part A — Currency conversion (ELLS 3.11): Extend the currency-conversion
example from lecture so that code such as the following will work:
5.dollars.in(:euros)
10.euros.in(:rupees)
def computeQValueFromValues(self, state, action):
"""
Compute the Q-value of action in state from the
value function stored in self.values.
"""
"*** YOUR CODE HERE ***"
#for this state and action, get list of probabilities for
#the legal transitions to new states for this state
#if "North" or "South" is action --returns (northState,1-self.noise),
#followed by (westState, self.noise/2.0) and (eastState, self.noise/2)
def computeQValueFromValues(self, state, action):
"""
Compute the Q-value of action in state from the
value function stored in self.values.
"""
"*** YOUR CODE HERE ***"
#for this state and action, get list of probabilities for
#the legal transitions to new states for this state
#if "North" or "South" is action --returns (northState,1-self.noise),
#followed by (westState, self.noise/2.0) and (eastState, self.noise/2)
Output from code is in comments at bottom - not sure what I'm doing wrong here, as you will see in
the output.
# -*- coding: utf-8 -*-
=begin
Karen West - Saas1 - homework#1 question #7 - April 7th, 2013
HW 1-7: Iterators, Blocks, Yield
Given two collections (of possibly different lengths), we want to get the Cartesian product of the sequences. A Cartesian product is a sequence that enumerates every possible pair from the two collections, where the pair consists of one element from each collection. For example, the Cartesian product (denoted by ×) of the sequences a = [:a, :b, :c] and b = [4, 5] is:
module Enumerable
def initialize(seq1, seq2)
puts "Enumerable initialize"
puts "seq1"
puts seq1
puts "seq2"
puts seq2
@seq1 = seq1
@seq2 = seq2
#return @seq1,@seq2