Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Week7 HW #102

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
45ca241
Updated roster position #4
kewpiedoll Jan 15, 2014
45d3363
Updated position roster #4
kewpiedoll Jan 15, 2014
eeb4557
Add in-class examples
kewpiedoll Jan 15, 2014
916f001
finished homework
kewpiedoll Jan 17, 2014
f6ad362
appended question 5
kewpiedoll Jan 17, 2014
1cd94df
upstream updates
kewpiedoll Jan 17, 2014
1beb438
completed hw 2
kewpiedoll Jan 23, 2014
e23bfbc
in class work on hw2
kewpiedoll Jan 24, 2014
342e152
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Jan 24, 2014
0e9dae7
Finished HW week3 and some exercise changes
kewpiedoll Jan 31, 2014
72802e8
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Jan 31, 2014
1840c8d
HW week4
kewpiedoll Feb 7, 2014
f4dc1b8
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Feb 7, 2014
0a98a2c
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Feb 7, 2014
397632f
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Feb 14, 2014
e651b6b
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Feb 21, 2014
a9eb285
week7 hw
kewpiedoll Feb 28, 2014
54bcd65
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Feb 28, 2014
69d1942
Merge branch 'master' of https://github.com/UWE-Ruby/RubyWinter2014
kewpiedoll Mar 7, 2014
086650a
added final from elsewhere so I can push it
kewpiedoll Mar 13, 2014
70e4cd3
git not working right, tried new folder name (not 'final')
kewpiedoll Mar 14, 2014
c6a120c
stopped work on tictactoe
kewpiedoll Mar 14, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions final
Submodule final added at d2b63e
12 changes: 7 additions & 5 deletions midterm/instructions_and_questions.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Instructions for Mid-Term submission and Git Review (10pts):
- Create a git repository for your answers
- Add and Commit as you work through the questions and programming problems
- Your git log should reflect your work, don't just commit after you have finished working
- Use .gitignore to ignore any files that are not relevant to the midterm
- E-mail me your ssh public key
DONE - Create a git repository for your answers
(OK) - Add and Commit as you work through the questions and programming problems
(OK) - Your git log should reflect your work, don't just commit after you have finished working
(to learn...) - Use .gitignore to ignore any files that are not relevant to the midterm
DONE - E-mail me your ssh public key
- I will email you back with your repository name
- Add a remote to your git repository: [email protected]:RubyWinter2014/YOURREPOSITORYNAME.git
- Push your changes to the remote
Expand All @@ -15,7 +15,9 @@ Instructions for Mid-Term submission and Git Review (10pts):
- What is the difference between how a String, a symbol, a FixNum, and a Float are stored in Ruby?
- Are these two statements equivalent? Why or Why Not?
1. x, y = "hello", "hello"
different object_id
2. x = y = "hello"
same object id
- What is the difference between a Range and an Array?
- Why would I use a Hash instead of an Array?
- What is your favorite thing about Ruby so far?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'rspec/mocks/standalone'
require 'rspec/mocks/standalone'
require 'rspec/expectations'
Given /^I start a new Tic\-Tac\-Toe game$/ do
@game = TicTacToe.new
Expand Down
157 changes: 157 additions & 0 deletions tic-tac-toe/features/step_definitions/tic-tac-toe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Did not have a chance to get too far on this.
# I went off on my own and not following the tests because they weren't passing anyways
# So far the program can do this:
# - Start game
# - Computer picks who goes first and who is X/O
# - User can fill up the board with their marker
# - User cannot add invalid input or use taken cell

class TicTacToe

attr_accessor :player
attr_accessor :current_player_var
@current_player_var = ""


SYMBOLS = ["X", "O"]

def player= name
@name = name
@move_count = 0
@cell_status = {
"A1" => false,
"A2" => false,
"A3" => false,
"B1" => false,
"B2" => false,
"B3" => false,
"C1" => false,
"C2" => false,
"C3" => false,
}
@cell_owner = {
"A1" => nil,
"A2" => nil,
"A3" => nil,
"B1" => nil,
"B2" => nil,
"B3" => nil,
"C1" => nil,
"C2" => nil,
"C3" => nil,
}
end

def welcome_player
choose_marker
"Welcome #{@name}! You are #{@player_symbol} and compy is #{@computer_symbol}"
end

def choose_marker
@player_symbol = SYMBOLS.sample
if @player_symbol == "X"
@computer_symbol = "O"
else
@computer_symbol = "X"
end
end

def player_symbol
@player_symbol
end

def computer_symbol
@computer_symbol
end

def current_player
if @current_player_var == "Computer"
puts "Computer goes."
@current_player_var = @name
@player = @name
elsif @current_player_var == @name
@current_player_var = "Computer"
else
@current_player_var = [@name, "Computer"].sample
end
end

def draw_board
draw_line = "-----------"
drawA1 = @cell_status["A1"] ? " #{@cell_owner["A1"]} |" : " |"
drawA2 = @cell_status["A2"] ? " #{@cell_owner["A2"]} " : " "
drawA3 = @cell_status["A3"] ? "| #{@cell_owner["A3"]}" : "|"
puts "#{drawA1}#{drawA2}#{drawA3}"
puts draw_line
drawB1 = @cell_status["B1"] ? " #{@cell_owner["B1"]} |" : " |"
drawB2 = @cell_status["B2"] ? " #{@cell_owner["B2"]} " : " "
drawB3 = @cell_status["B3"] ? "| #{@cell_owner["B3"]}" : "|"
puts "#{drawB1}#{drawB2}#{drawB3}"
puts draw_line
drawC1 = @cell_status["C1"] ? " #{@cell_owner["C1"]} |" : " |"
drawC2 = @cell_status["C2"] ? " #{@cell_owner["C2"]} " : " "
drawC3 = @cell_status["C3"] ? "| #{@cell_owner["C3"]}" : "|"
puts "#{drawC1}#{drawC2}#{drawC3}"
puts "\n======================= NEXT TURN ==========================="
end

def over?
if player_won? or computer_won?
true
else
false
end
end

def player_won?
if @cell_owner["A1"] == @player_marker
#puts @cell_owner["A1"]
#true
end
end

def computer_won?
end

def draw?
if @cell_status.has_value?(false)
true
else
false
end
end

def player_move
proper_move = false
while proper_move == false
input = gets.chomp
if input !~ /[A-C][1-3]/
print "Enter A, B, or C for the row and 1, 2, or 3 for the column: "
elsif @cell_status[input] == true
print "Cell taken, please re-enter: "
else
proper_move = true
end
end
@cell_status[input] = true
@cell_owner[input] = @player_symbol

p @cell_status # for testing
p @cell_owner # for testing
end

def indicate_player_turn
print "#{@name}'s move: "
end

def computer_move
end

def current_state
draw_board
end

def determine_winner
end

end
5 changes: 3 additions & 2 deletions week7/homework/play_game.rb → tic-tac-toe/play_game.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
require './features/step_definitions/tic-tac-toe.rb'
require './features/step_definitions/tic-tac-toe.rb'

@game = TicTacToe.new
puts "What is your name?"
@game.player = gets.chomp
puts @game.welcome_player


until @game.over?
case @game.current_player
when "Computer"
@game.computer_move
when @game.player
@game.indicate_palyer_turn
@game.indicate_player_turn
@game.player_move
end
puts @game.current_state
Expand Down
13 changes: 13 additions & 0 deletions tic-tac-toe/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Test

print "Input something: "
check = false
while check == false
input = gets.chomp
check = true
end
puts "#{input} is what you entered."

end

c = Test.new
12 changes: 4 additions & 8 deletions week1/exercises/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

# When this example fails,
# it will show "expected" as 2, and "actual" as 1
1.should eq 2
1.should_not eq 2

end

Expand All @@ -66,13 +66,6 @@
"Renée".should have(5).characters
end

it "should check how to spell my name" do
"Renée".should include("ée")
end

end

context "Examples for in-class test exploration" do
it "should know order of operations" do
# Fix the Failing Test
# Order of Operations is Please Excuse My Dear Aunt Sally:
Expand All @@ -91,6 +84,9 @@
"Field".should include('ie')
end

it "should check basic spelling" do
"Field".should include('ie')
end
end

end
8 changes: 8 additions & 0 deletions week1/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ Chapter 3 Classes, Objects, and Variables
p.86-90 Strings (Strings section in Chapter 6 Standard Types)

1. What is an object?
Objects are instances created by classes containing state and behavior.

2. What is a variable?
Variables are a device used to store data. In Ruby a variable is a reference to an object.

3. What is the difference between an object and a class?
An object is one particular instance of a class. An object may have state and behavior unique to that
instance even though it was generated from the same class. A class is code read by the interpreter to create objects.

4. What is a String?
A string is a literal sequence of characters. In ruby, Strings are objects.

5. What are three messages that I can send to a string object? Hint: think methods
length, empty?, and encoding


6. What are two ways of defining a String literal? Bonus: What is the difference between them?
You can use single or double quotes (' or "). The double quotes allows for many more escape sequences and ruby expressions to be included. You can also use %q or %Q which behave much like ' and ".
5 changes: 5 additions & 0 deletions week1/homework/string_example.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@my_string = "Renée is a fun teacher. Ruby is a really cool programming language"
puts @my_string.size
result = []
result = @my_string.split(/\./)
puts result
11 changes: 7 additions & 4 deletions week1/homework/strings_and_rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
before(:all) do
@my_string = "Renée is a fun teacher. Ruby is a really cool programming language"
end
it "should be able to count the charaters"
it "should be able to count the charaters" do
@my_string.size.should eq 66
end
it "should be able to split on the . charater" do
pending
result = #do something with @my_string here
result = []
result = @my_string.split(/\./)
result.should have(2).items
end
it "should be able to give the encoding of the string" do
pending 'helpful hint: should eq (Encoding.find("UTF-8"))'
@my_string.encoding.should eq (Encoding.find("UTF-8"))
# pending 'helpful hint: should eq (Encoding.find("UTF-8"))'
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions week2/homework/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format nested
5 changes: 5 additions & 0 deletions week2/homework/questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ Containers, Blocks, and Iterators
Sharing Functionality: Inheritance, Modules, and Mixins

1. What is the difference between a Hash and an Array?
A hash uses a key / value pair to store data as an indexed collection where the key is any object. An array stores a collection that is accessible by a key that is an integer.

2. When would you use an Array over a Hash and vice versa?
Arrays acces is more efficient but a hash gives the user more flexibility over the collection. Hashes enumerate values in the order that the associated keys were given.

3. What is a module? Enumerable is a built in Ruby module, what is it?
Modules are a grouping of methods, classes and constants. Enumerable is a mixin that allows use of the host class' each method.

4. Can you inherit more than one thing in Ruby? How could you get around this problem?
Ruby is a single-inheritance language though you cna use mixins that essentially give the user multiple-inheritance ability.

5. What is the difference between a Module and a Class?
A module is a grouping of code though it is not instantiated as classes are. There are no instances of a module that get made.
56 changes: 56 additions & 0 deletions week2/homework/simon_says.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module SimonSays

def echo word
word
end

def shout word
"#{word.upcase}"
end

def repeat(word)
word + ' ' + word
end

def repeat(word, n=2)
if n > 2
string = ""
while n > 1
string += "#{word} "
n -= 1
end
string += "#{word}"
else
"#{word} #{word}"
end
end

def start_of_word(word, n)
a = 0
string = ""
while a <= n
string += word[a]
n -= 1
a += 1
end
string
end

def first_word(phrase)
word = phrase.split
word[0]
end

end

#class RunSimon
# include SimonSays
#end

#below was only for testing
# w = RunSimon.new
# p w.echo("Hello")
# p w.echo("Hello")
# p w.shout("Hello")
# p w.repeat("hello", 3)
# p w.first_word("Hello there")
Loading