From a90fb6aae786c8de1e97f764615f034077b6e7f3 Mon Sep 17 00:00:00 2001 From: Kody Wilson Date: Mon, 27 Jan 2014 07:21:19 -0800 Subject: [PATCH 01/20] First commit with change to roster, rspec_spec.rb (in class exercise), and one answer to a homework question. Pushing to origin so I can pull from a different computer and finish homework. --- week1/exercises/roster.txt | 1 + week1/exercises/rspec_spec.rb | 4 ++-- week1/homework/questions.txt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/week1/exercises/roster.txt b/week1/exercises/roster.txt index 21b0964..05d6f39 100644 --- a/week1/exercises/roster.txt +++ b/week1/exercises/roster.txt @@ -20,3 +20,4 @@ 18, 19, 20, Zack Walkingstick, zackwalkingstick@gmail.com, zackwalkingstick, no twitter, @zack +21, Kody Wilson, kodywilson@gmail.com, kodywilson, @kodykwilson, Kody Wilson diff --git a/week1/exercises/rspec_spec.rb b/week1/exercises/rspec_spec.rb index 1152c22..7641ef2 100644 --- a/week1/exercises/rspec_spec.rb +++ b/week1/exercises/rspec_spec.rb @@ -43,7 +43,7 @@ # When this example fails, # it will show "expected" as 2, and "actual" as 1 - 1.should eq 2 + 1.should eq 1 end @@ -80,7 +80,7 @@ ((((1+2)-5)*6)/2).should eq -6 end it "should count the characters in your name" do - "Tom".should have(3).characters + "Kody".should have(4).characters end it "should check basic math" do diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index 2257bb9..80f733d 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -3,6 +3,7 @@ Chapter 3 Classes, Objects, and Variables p.86-90 Strings (Strings section in Chapter 6 Standard Types) 1. What is an object? +Everything you manipulate is an object, and the results of those manipulations are themselves objects. 2. What is a variable? From 7c6391e34c90784e8833f9e2fca4e0f4b600ec8a Mon Sep 17 00:00:00 2001 From: kodywilson Date: Mon, 27 Jan 2014 14:48:34 -0800 Subject: [PATCH 02/20] Altered .gitignore to add .project which was created by Aptana Studio 3 when I added the UWERuby class project (by cloning my fork). --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e43b0f9..d825d8a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +.project From 9cb6cbf1f834800f321e34c98d3aff8e5f40174e Mon Sep 17 00:00:00 2001 From: kodywilson Date: Mon, 27 Jan 2014 16:34:06 -0800 Subject: [PATCH 03/20] Finished answering questions and doing the homework for week 1. --- week1/homework/questions.txt | 6 ++++++ week1/homework/strings_and_rspec_spec.rb | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/week1/homework/questions.txt b/week1/homework/questions.txt index 80f733d..189e6fb 100644 --- a/week1/homework/questions.txt +++ b/week1/homework/questions.txt @@ -6,11 +6,17 @@ p.86-90 Strings (Strings section in Chapter 6 Standard Types) Everything you manipulate is an object, and the results of those manipulations are themselves objects. 2. What is a variable? +A reference to an object. 3. What is the difference between an object and a class? +A class is a way to define methods for objects and is an object itself. 4. What is a String? +Strings are objects holding sequences of characters. 5. What are three messages that I can send to a string object? Hint: think methods +length, split, upcase 6. What are two ways of defining a String literal? Bonus: What is the difference between them? +single quotes = fewer escape sequences, usually used when you don't need something in the quotes to change (no interpolation). +double quotes = lots of escape sequences and interpolation, ie. "#{some_var} is awesome!" to add some_var to string. diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index ea79e4c..35b61f4 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -12,14 +12,16 @@ 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 characters" do + @my_string.should have(66).characters + end it "should be able to split on the . charater" do - pending - result = #do something with @my_string here - result.should have(2).items + 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"))' + encode = @my_string.encoding + encode.should eq (Encoding.find("UTF-8")) end end end From 30610be51d19d9ce340c026b34eeb4f5820e9678 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Tue, 28 Jan 2014 16:55:40 -0800 Subject: [PATCH 04/20] Completed all week 2 homework. --- week2/homework/questions.txt | 12 ++++++++++++ week2/homework/simon_says.rb | 20 ++++++++++++++++++++ week2/homework/simon_says_spec.rb | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 week2/homework/simon_says.rb diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 939e42d..302da13 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -3,11 +3,23 @@ Containers, Blocks, and Iterators Sharing Functionality: Inheritance, Modules, and Mixins 1. What is the difference between a Hash and an Array? +Arrays are indexed by integers while hashes are indexed with objects of any type. +In a hash, each value has two objects, the index (key) and associated entry. 2. When would you use an Array over a Hash and vice versa? +You would use an array if you do not need non-integer indexing as arrays are more efficient than hashes. +Maybe a better way to put it is that sometimes being able to reference values by their keys +is super handy so you would choose a hash in that case. 3. What is a module? Enumerable is a built in Ruby module, what is it? +Modules are a way of grouping together methods, classes, and constants. +They provide namespace and prevent name clashes and support the mixin facility. +Enumerable is a standard mixin, implementing a bunch of methods in terms of the host class’s +each method. 4. Can you inherit more than one thing in Ruby? How could you get around this problem? +A Ruby class has only one direct parent, so Ruby is a single-inheritance language. +To circumvent this problem, Ruby classes can include the functionality of any number of mixins. 5. What is the difference between a Module and a Class? +Modules support the mixin facility and prevent name clashes. diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..76f9434 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,20 @@ +module SimonSays + def echo(greet) + greet + end + def shout(scream) + scream.upcase + end + def repeat(greet) + ("#{greet} " * 2).chop + end + def repeat(greet, quant=2) + ("#{greet} " * quant).chop + end + def start_of_word (word, place) + word[0...place] + end + def first_word(phrase) + phrase.split.first + end +end \ No newline at end of file diff --git a/week2/homework/simon_says_spec.rb b/week2/homework/simon_says_spec.rb index 7f329e5..3ea948d 100644 --- a/week2/homework/simon_says_spec.rb +++ b/week2/homework/simon_says_spec.rb @@ -2,7 +2,7 @@ require "./simon_says.rb" describe SimonSays do - include SimonSays # Hint: Inclusion is different than SimonSays.new (read about modules) + include SimonSays # Hint: We are just calling methods, we are not passing a message to a SimonSays object. it "should echo hello" do From b71d960ab51108384b0e78f0e49dab7de4acd692 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Tue, 28 Jan 2014 16:59:57 -0800 Subject: [PATCH 05/20] Removed extra repeat code block in simon_says.rb --- week2/homework/simon_says.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb index 76f9434..a31656f 100644 --- a/week2/homework/simon_says.rb +++ b/week2/homework/simon_says.rb @@ -5,9 +5,6 @@ def echo(greet) def shout(scream) scream.upcase end - def repeat(greet) - ("#{greet} " * 2).chop - end def repeat(greet, quant=2) ("#{greet} " * quant).chop end From b8fffac34f0f9577db15fcef193d9ca9f661b848 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Wed, 29 Jan 2014 16:39:34 -0800 Subject: [PATCH 06/20] Adding some changes to the week3 in class exercises as I follow along. --- week3/exercises/.rspec | 2 ++ week3/exercises/book.rb | 19 +++++++++++++++++-- week3/exercises/book_spec.rb | 32 ++++++++++++++++++++++++++++---- week3/homework/.rspec | 2 ++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 week3/exercises/.rspec create mode 100644 week3/homework/.rspec diff --git a/week3/exercises/.rspec b/week3/exercises/.rspec new file mode 100644 index 0000000..b36b4b5 --- /dev/null +++ b/week3/exercises/.rspec @@ -0,0 +1,2 @@ +--color +--format nested \ No newline at end of file diff --git a/week3/exercises/book.rb b/week3/exercises/book.rb index c13e4d4..6433c67 100644 --- a/week3/exercises/book.rb +++ b/week3/exercises/book.rb @@ -1,7 +1,22 @@ class Book - def pages - + attr_accessor :pages, :title + + @@library_count = 0 + + def self.library_count + @@library_count + end + + def initialize pages = 1, title="N/A" + @pages = pages + @title = title + @@library_count += 1 + end + + def happy + $global_hello = "hello" + "There are #{@pages} happy pages in this book" end end \ No newline at end of file diff --git a/week3/exercises/book_spec.rb b/week3/exercises/book_spec.rb index 72bc203..0f78b78 100644 --- a/week3/exercises/book_spec.rb +++ b/week3/exercises/book_spec.rb @@ -2,9 +2,33 @@ describe Book do - it "should have a pages" do - book = Book.new - book.should respond_to "pages" + before :each do + @book = Book.new 542, "Programming Ruby" end - + + context "::library_count" do + it "should tell us how many books are in our library" do + 3.times{ Book.new 3 } + Book.library_count.should eq 4 + end + end + + context "#pages" do + + it "should have a pages" do + @book.should respond_to "pages" + end + + it "should allow us to set the number of pages" do + @book.pages.should eq 542 + end + + end + + context "#title" do + it "should let us read the title" do + @book.title.should eq "Programming Ruby" + end + end + end \ No newline at end of file diff --git a/week3/homework/.rspec b/week3/homework/.rspec new file mode 100644 index 0000000..b36b4b5 --- /dev/null +++ b/week3/homework/.rspec @@ -0,0 +1,2 @@ +--color +--format nested \ No newline at end of file From 132f16711aeb73a579b6dced55f88ab9e385f09b Mon Sep 17 00:00:00 2001 From: kodywilson Date: Fri, 31 Jan 2014 14:46:33 -0800 Subject: [PATCH 07/20] Committing changes made on work computer to my fork. These are the in class exercises from week 3. --- week3/exercises/book.rb | 35 +++++++++++++++++++--------------- week3/exercises/human.rb | 7 +++++++ week3/exercises/monster.rb | 5 +++++ week3/exercises/other_thing.rb | 5 +++++ week3/exercises/vampire.rb | 8 ++++++++ week3/exercises/zombie.rb | 9 +++++++++ 6 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 week3/exercises/human.rb create mode 100644 week3/exercises/other_thing.rb create mode 100644 week3/exercises/zombie.rb diff --git a/week3/exercises/book.rb b/week3/exercises/book.rb index 6433c67..c8f6e01 100644 --- a/week3/exercises/book.rb +++ b/week3/exercises/book.rb @@ -1,22 +1,27 @@ -class Book +$global_hello = "hi there" - attr_accessor :pages, :title +module Library + class Book + HELLO = "hello I shouldn't change..." + + attr_accessor :pages, :title - @@library_count = 0 + @@library_count = 0 - def self.library_count - @@library_count - end + def self.library_count + @@library_count + end - def initialize pages = 1, title="N/A" - @pages = pages - @title = title - @@library_count += 1 - end + def initialize pages = 1, title="N/A" + @pages = pages + @title = title + @@library_count += 1 + end - def happy - $global_hello = "hello" - "There are #{@pages} happy pages in this book" - end + def happy + $global_hello = "hello" + "There are #{@pages} happy pages in this book" + end + end end \ No newline at end of file diff --git a/week3/exercises/human.rb b/week3/exercises/human.rb new file mode 100644 index 0000000..c5edd4e --- /dev/null +++ b/week3/exercises/human.rb @@ -0,0 +1,7 @@ +require_relative 'named_thing' +require_relative 'other_thing' + +class Human + include NamedThing + include OtherThing +end diff --git a/week3/exercises/monster.rb b/week3/exercises/monster.rb index 013c3d2..4f9beda 100644 --- a/week3/exercises/monster.rb +++ b/week3/exercises/monster.rb @@ -11,4 +11,9 @@ def initialize(noc, legs, name="Monster", vul = [], dangers = []) @dangers = dangers @legs = legs end + + def attack! human + puts "hi from Monster" + end + end diff --git a/week3/exercises/other_thing.rb b/week3/exercises/other_thing.rb new file mode 100644 index 0000000..f51fdd2 --- /dev/null +++ b/week3/exercises/other_thing.rb @@ -0,0 +1,5 @@ +module OtherThing + def say_name + "hello" + end +end \ No newline at end of file diff --git a/week3/exercises/vampire.rb b/week3/exercises/vampire.rb index 764adf6..d3c1207 100644 --- a/week3/exercises/vampire.rb +++ b/week3/exercises/vampire.rb @@ -3,4 +3,12 @@ class Vampire < Monster def initialize(noc=true, legs=2, name ="Vampire", vul=[:garlic, :sunlight], dangers=[:bites]) super(noc,legs,name,vul,dangers) end + + def bite! human + + end + + def attack! human + puts "hi from Vampire" + end end diff --git a/week3/exercises/zombie.rb b/week3/exercises/zombie.rb new file mode 100644 index 0000000..cb9321c --- /dev/null +++ b/week3/exercises/zombie.rb @@ -0,0 +1,9 @@ +require_relative 'named_thing' + +class Zombie + include NamedThing + + def say_name + "uuurrrrggggghhhhh #{@name}" + end +end \ No newline at end of file From 3b477a3d906cb8621152100811b375de0d8908a9 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 6 Feb 2014 16:30:07 -0800 Subject: [PATCH 08/20] Week 3 homework (Calculator). Still need to do questions. --- week3/homework/calculator.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 week3/homework/calculator.rb diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb new file mode 100644 index 0000000..e8a3dac --- /dev/null +++ b/week3/homework/calculator.rb @@ -0,0 +1,14 @@ +class Calculator + def sum numbers + numbers.inject 0, :+ + end + def multiply *numbers + numbers.flatten.inject :* + end + def pow x, y + x**y + end + def fac x + multiply (1..x).to_a + end +end \ No newline at end of file From 578c90b71fa6c940923d88fdab5bfeb2d8e5bb90 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Wed, 12 Feb 2014 16:33:40 -0800 Subject: [PATCH 09/20] One correction to the week 3 homework and I answered the questions for week 3. --- week3/homework/calculator.rb | 2 +- week3/homework/questions.txt | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb index e8a3dac..a452cf6 100644 --- a/week3/homework/calculator.rb +++ b/week3/homework/calculator.rb @@ -3,7 +3,7 @@ def sum numbers numbers.inject 0, :+ end def multiply *numbers - numbers.flatten.inject :* + numbers.flatten.inject 1, :* end def pow x, y x**y diff --git a/week3/homework/questions.txt b/week3/homework/questions.txt index dfb158d..51a4cba 100644 --- a/week3/homework/questions.txt +++ b/week3/homework/questions.txt @@ -5,11 +5,21 @@ Please Read: - Chapter 22 The Ruby Language: basic types (symbols), variables and constants 1. What is a symbol? +A symbol is an identifier corresponding to a string of characters, often a name. +They cannot be changed, only overwritten. 2. What is the difference between a symbol and a string? +Symbols are immutable (cannot be changed, same object id) while strings are not. 3. What is a block and how do I call a block? +A block is a chunk of code enclosed between either braces or the keywords do +and end. Blocks can take parameters and are called by a method (like they are +another parameter passed to a method). 4. How do I pass a block to a method? What is the method signature? +You just put the code after the invocation of the method. I think a method signature +is the name of the method and the paramaters that are required. 5. Where would you use regular expressions? +Any time you need to match a pattern in a string. Like say you were trying to +see if the word "kitten" is in a line of text or if a line starts with "Once", etc. From b4d9c4094e7835d33794f8351444d1e433c9b0f6 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Tue, 18 Feb 2014 14:57:54 -0800 Subject: [PATCH 10/20] Week 4 homework. --- week4/homework/questions.txt | 27 +++++++++++++++++++++++++++ week4/homework/worker.rb | 7 +++++++ 2 files changed, 34 insertions(+) create mode 100644 week4/homework/worker.rb diff --git a/week4/homework/questions.txt b/week4/homework/questions.txt index 187b3d3..789e001 100644 --- a/week4/homework/questions.txt +++ b/week4/homework/questions.txt @@ -3,12 +3,39 @@ Chapter 10 Basic Input and Output The Rake Gem: http://rake.rubyforge.org/ 1. How does Ruby read files? +It uses the base class IO, with the sub class, File. 2. How would you output "Hello World!" to a file called my_output.txt? +Here is one way, using irb: +xabv@V00970630 ~/code/ruby/ +$ irb +irb(main):001:0> File.open("my_output.txt", "w") do |file| +irb(main):002:1* file.puts "Hello World!" +irb(main):003:1> end +=> nil +irb(main):004:0> exit + +xabv@V00970630 ~/code/ruby/ +$ ls +my_output.txt + +xabv@V00970630 ~/code/ruby/ +$ cat my_output.txt +Hello World! 3. What is the Directory class and what is it used for? +Objects of class Dir (directory) are directory streams representing +directories in the underlying filesystem. They provide many methods +to manipulate, delete, list, etc. directories and their contents. 4. What is an IO object? +An IO object is a bidirectional channel between a Ruby program and some +external resource. 5. What is rake and what is it used for? What is a rake task? +Rake is a gem that provides capabilities similar to make (you can build +programs with it) using settings found in rakefiles. +A rake task is a section of code in a rakefile that performs a job. +It might do a unit test or build a tarball for example. I guess you +could think of it as one piece of an install for a ruby program. diff --git a/week4/homework/worker.rb b/week4/homework/worker.rb new file mode 100644 index 0000000..6b952fb --- /dev/null +++ b/week4/homework/worker.rb @@ -0,0 +1,7 @@ +module Worker + def self.work n = 1 + x = nil + n.times { x = yield } + x + end +end \ No newline at end of file From 80b54f73e9dd7d713bb74a83c9a32671f6dd37da Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 27 Feb 2014 07:22:27 -0800 Subject: [PATCH 11/20] Week 5 in-class exercises. --- week5/exercises/Rakefile.rb | 40 ++++++++++++++++++++++++++++++++++ week5/exercises/ex_rakefile.rb | 10 +++++++++ 2 files changed, 50 insertions(+) create mode 100644 week5/exercises/Rakefile.rb create mode 100644 week5/exercises/ex_rakefile.rb diff --git a/week5/exercises/Rakefile.rb b/week5/exercises/Rakefile.rb new file mode 100644 index 0000000..598ae89 --- /dev/null +++ b/week5/exercises/Rakefile.rb @@ -0,0 +1,40 @@ +# names and class Rakefile + +desc "Read names from file and print them out" +task :print_names do + file_helper("names") do |line| + puts line + end +end + +desc "Creates class directory" +task :make_directory do + Dir.mkdir "class" unless Dir.exists? "class" +end + +desc "Create directories using names in class directory" +task :name_directories => [:make_directory] do + Dir.chdir("class") + file_helper("../names") do |line| + Dir.mkdir line unless Dir.exists? line + end + Dir.chdir("..") +end + +desc "clean up the directories we created" +task :remove_all_dirs => [:name_directories] do + Dir.chdir("class") + file_helper("../names") do |line| + Dir.rmdir line if Dir.exists? line + end + Dir.chdir("..") + Dir.rmdir("class") +end + +def file_helper file_name + File.open(file_name) do |f| + f.each do |line| + yield line.chomp + end + end +end diff --git a/week5/exercises/ex_rakefile.rb b/week5/exercises/ex_rakefile.rb new file mode 100644 index 0000000..afb06a5 --- /dev/null +++ b/week5/exercises/ex_rakefile.rb @@ -0,0 +1,10 @@ +task :default => [:say_hello, :say_hi] +desc "Outputs hello world" +task :say_hello do + puts "hello world" +end + +desc "Outputs Hi" +task :say_hi do + puts "Hi" +end \ No newline at end of file From ec81fa42330fab750b02e035768e3cfeb2d981ee Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 27 Feb 2014 07:53:14 -0800 Subject: [PATCH 12/20] Built my test gem, jim_gem_gym --- week6/homework/jim_gem_gym/jim_gem_gym-0.0.0.gem | Bin 0 -> 4096 bytes week6/homework/jim_gem_gym/jim_gem_gym.gemspec | 12 ++++++++++++ week6/homework/jim_gem_gym/lib/jim_gem_gym.rb | 1 + 3 files changed, 13 insertions(+) create mode 100644 week6/homework/jim_gem_gym/jim_gem_gym-0.0.0.gem create mode 100644 week6/homework/jim_gem_gym/jim_gem_gym.gemspec create mode 100644 week6/homework/jim_gem_gym/lib/jim_gem_gym.rb diff --git a/week6/homework/jim_gem_gym/jim_gem_gym-0.0.0.gem b/week6/homework/jim_gem_gym/jim_gem_gym-0.0.0.gem new file mode 100644 index 0000000000000000000000000000000000000000..99076cc1f287da57bde9b927c97848eb7ad81992 GIT binary patch literal 4096 zcmc~zElEsCEJ@T$uVSDTFaQD*6B7my4Fu@4fw_ShgQ1bJfw7sXxuJnMgMp#3iHRwL zf&r}@glukUaY8f@({lvJcp)zuyWAUQn?xXthOZVQb)%c!u>5|X0+4}c= zmW75s44rlRvDr5Bl*qkm>#wwTuDNZUed8#@!HS@Y$9vv+-do%*KV?(J6?-T9wR#RV z&9kD^d=@{f^@&UDWHkOP5F8fp@b(SakDH}8x122V`BGcv+1GNd^_*(!Csyyyt+GAB z$JXCpV64*-`}xVPtg@@`G|hUW=IyfN{lg^dD`LfUEimq|#_cC+aV>jYJUJ{Md8o0< zJjylPV;NBRMCydJxt2}Gf!nV4yZ61hVpg@ldXw?&vOVd`td|7{+08!r;)?6)@9$b7 z!zX=uaqF$C^VE_^YV^Kf9l0HZPGQJobd8-+^T7hoEkrDKM|`dyyf`bDp=?+*4t_P^a;ij0u{>FP${HyTyL-&V2iM|3+p?(iS-H19QMY z=6@qYWAyxQY-%!^|0#)AV)Y{O|EZHcm(HI$)9dfg`sh^5-bE^GtC*RcnVF4+h1r-n z9G3I)^!P~f^!D)fob@@&%X_BrmG7A|XC*{1cE&d2^e`~UCe z`|rE;^-r&VnR{B!$Ikv>frX9DyG=U(_V}&8T>7iZum9$L?fu{XsGs)u?)Wmm(mq6^ zZ{m?cN6RTI{I!4DHMB`>*_kLK{%L(+X0TH8&yUuhtoHup?=HJBM}BX2h?OtrZ9}Il zt}bWJjVohL&$#h)oo!V|0rTzL9Y)`df6p&fwDVr8qq1~qm5MNzMKo23iG)@mAj z{d2e4=UvmMDFOY)zv|pLMO9ANZ?V-=cqbVV-zIwN-Lf3{3-M_ku}qb5n!SRyadYg~ zp0f($x9sx!Bbwv&PDkC_{KE3ym(ol9EN;7J>~yc+w|ti8<1^{qpFc#Vdzo8iu8U`% zmv448sbo_4g-t!CQzzSaNi2M)oU*-9?cgQV2n{=_PYbR97(Jh`dqZ(GVC7fzc44AOrvpjxH$x literal 0 HcmV?d00001 diff --git a/week6/homework/jim_gem_gym/jim_gem_gym.gemspec b/week6/homework/jim_gem_gym/jim_gem_gym.gemspec new file mode 100644 index 0000000..8737a16 --- /dev/null +++ b/week6/homework/jim_gem_gym/jim_gem_gym.gemspec @@ -0,0 +1,12 @@ +Gem::Specification.new do |s| + s.name = 'jim_gem_gym' + s.version = '0.0.0' + s.date = '2014-02-27' + s.summary = "Creating a test gem" + s.description = "A gem to learn how to make gems." + s.authors = ["Kody Wilson"] + s.email = 'kodywilson@gmail.com' + s.homepage = 'http://rubygems.org/gems/jim_gem_gym' + s.license = 'MIT' + s.files = ["lib/jim_gem_gym.rb"] +end diff --git a/week6/homework/jim_gem_gym/lib/jim_gem_gym.rb b/week6/homework/jim_gem_gym/lib/jim_gem_gym.rb new file mode 100644 index 0000000..d3ee0ef --- /dev/null +++ b/week6/homework/jim_gem_gym/lib/jim_gem_gym.rb @@ -0,0 +1 @@ +puts "Hi Existence" From 27b506aa9d94d91cd86602e7913e8e508c2bd24b Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 27 Feb 2014 09:39:32 -0800 Subject: [PATCH 13/20] Added executable to my learning gem, jim_gem_gym --- week6/homework/jim_gem_gym/bin/jim_gem_gym | 5 +++++ week6/homework/jim_gem_gym/jim_gem_gym-0.0.1.gem | Bin 0 -> 4096 bytes week6/homework/jim_gem_gym/jim_gem_gym-0.0.2.gem | Bin 0 -> 4096 bytes week6/homework/jim_gem_gym/jim_gem_gym.gemspec | 3 ++- week6/homework/jim_gem_gym/lib/jim_gem_gym.rb | 13 +++++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 week6/homework/jim_gem_gym/bin/jim_gem_gym create mode 100644 week6/homework/jim_gem_gym/jim_gem_gym-0.0.1.gem create mode 100644 week6/homework/jim_gem_gym/jim_gem_gym-0.0.2.gem diff --git a/week6/homework/jim_gem_gym/bin/jim_gem_gym b/week6/homework/jim_gem_gym/bin/jim_gem_gym new file mode 100644 index 0000000..131f5e0 --- /dev/null +++ b/week6/homework/jim_gem_gym/bin/jim_gem_gym @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require 'jim_gem_gym' + +puts Reality.new("benign").worldview diff --git a/week6/homework/jim_gem_gym/jim_gem_gym-0.0.1.gem b/week6/homework/jim_gem_gym/jim_gem_gym-0.0.1.gem new file mode 100644 index 0000000000000000000000000000000000000000..d8196ec1c321daa96481c93f1c492bbd845ed776 GIT binary patch literal 4096 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 Date: Thu, 27 Feb 2014 09:56:55 -0800 Subject: [PATCH 14/20] Added ability to take parameters to jim_gem_gym --- week6/homework/jim_gem_gym/bin/jim_gem_gym | 4 +++- week6/homework/jim_gem_gym/jim_gem_gym.gemspec | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/week6/homework/jim_gem_gym/bin/jim_gem_gym b/week6/homework/jim_gem_gym/bin/jim_gem_gym index 131f5e0..dd5fba4 100644 --- a/week6/homework/jim_gem_gym/bin/jim_gem_gym +++ b/week6/homework/jim_gem_gym/bin/jim_gem_gym @@ -2,4 +2,6 @@ require 'jim_gem_gym' -puts Reality.new("benign").worldview +paradigm = ARGV.first || "benign" + +puts Reality.new(paradigm).worldview diff --git a/week6/homework/jim_gem_gym/jim_gem_gym.gemspec b/week6/homework/jim_gem_gym/jim_gem_gym.gemspec index 412812e..55f86f7 100644 --- a/week6/homework/jim_gem_gym/jim_gem_gym.gemspec +++ b/week6/homework/jim_gem_gym/jim_gem_gym.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'jim_gem_gym' - s.version = '0.0.2' + s.version = '0.0.3' s.date = '2014-02-27' s.summary = "Creating a test gem" s.description = "A gem to learn how to make gems." From 9cbd4ea0df1150194a2a50c562d487e26d7deb6b Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 27 Feb 2014 10:21:52 -0800 Subject: [PATCH 15/20] Added Rakefile and rspec for tests. --- week6/homework/jim_gem_gym/Rakefile.rb | 3 +++ week6/homework/jim_gem_gym/jim_gem_gym-0.0.3.gem | Bin 0 -> 4096 bytes week6/homework/jim_gem_gym/spec/.rspec | 2 ++ .../jim_gem_gym/spec/jim_gem_gym_spec.rb | 9 +++++++++ 4 files changed, 14 insertions(+) create mode 100644 week6/homework/jim_gem_gym/Rakefile.rb create mode 100644 week6/homework/jim_gem_gym/jim_gem_gym-0.0.3.gem create mode 100644 week6/homework/jim_gem_gym/spec/.rspec create mode 100644 week6/homework/jim_gem_gym/spec/jim_gem_gym_spec.rb diff --git a/week6/homework/jim_gem_gym/Rakefile.rb b/week6/homework/jim_gem_gym/Rakefile.rb new file mode 100644 index 0000000..aee99c0 --- /dev/null +++ b/week6/homework/jim_gem_gym/Rakefile.rb @@ -0,0 +1,3 @@ +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new('spec') +task :default => :spec \ No newline at end of file diff --git a/week6/homework/jim_gem_gym/jim_gem_gym-0.0.3.gem b/week6/homework/jim_gem_gym/jim_gem_gym-0.0.3.gem new file mode 100644 index 0000000000000000000000000000000000000000..ce7e75c5f722005e391c741fc1dc0bb5ef1b5e5c GIT binary patch literal 4096 zcmc~zElEsCEJ@T$uVSDTFaQD*6B7my4Fu@4fw_?pgQ1bJfw7sniLtpUgMp#3iK!uj zf&r}@glukUaY8f@({lvJcp)zuyW=D-zro7SiI>&x6_l3AN*fVOEDeU zy<}V7>*og2Gx_Wy8YP*FJSX!9I<&t3TX1OoEtj^9x7mN~d~v|tY5m;=%?@?VizZl^ zdY=?&9P1s^%y zlMf0$h2Pxp$-`10TS0rPU`0w}xalv%wfCP zdT{l-1!sFFlpc3jxAta}w#lyhRj)1_exiG}=t?5WV2J?G3b|LQ4I$iJhUMJu-@t1sxh;A#C=`%d%g zfA@bemq%+YTjXb+fOQU`H?2M}$3HA~dm}R*)1}k{B&1ws0v1Z$` z$&T0BG4jUWYu7K7wep|lGEtggnP)5@Rh9qy?mfxmhs$eswHDucSYT0ih#eT@|Nk>H z1TZ9OGw_fT{sXNiIU_YWySOyBSg$fMH-|Q*0H|ujSO1%tn4{%?6Eh>z(fm)3w1LR~ zt&@DaZ#(d`z5glt?q2Yl!kWkvil;5siJPdst6+QiOilG%&6f=r(PIa!{pkGf3d#46uV+`C{WtZ`y&|>K8sGeG zma*q)OlfJ!TXEp(%FFF@RKi|pOjsj)({5GCDhGL6qZza3pZNXbWBeMs=M&Z$pZLu8 z<>AGfWokF|u3T7RQrTnr{Lm7Y_a`6mTw|Fb`TOtfg<40_qsu=AO6C!tPHnZ^k?hi~dcv{c@y}c81qS73Kg>+q zacjb@rmdO>DmR`B>-=7DBEq=Q!Ztwrx@kb!rxV+J%qIjV-2SBQu=M-Y)l54Z=M?hn z2s9R{DSz=~rwTW>Rs5wQk l!63Xh@#&AiN%!;rF)ZED%3i@lkAyI4$7l$QhQNpm0RUX%qmcjr literal 0 HcmV?d00001 diff --git a/week6/homework/jim_gem_gym/spec/.rspec b/week6/homework/jim_gem_gym/spec/.rspec new file mode 100644 index 0000000..b3eb8b4 --- /dev/null +++ b/week6/homework/jim_gem_gym/spec/.rspec @@ -0,0 +1,2 @@ +--color +--format documentation \ No newline at end of file diff --git a/week6/homework/jim_gem_gym/spec/jim_gem_gym_spec.rb b/week6/homework/jim_gem_gym/spec/jim_gem_gym_spec.rb new file mode 100644 index 0000000..faa5a79 --- /dev/null +++ b/week6/homework/jim_gem_gym/spec/jim_gem_gym_spec.rb @@ -0,0 +1,9 @@ +require 'jim_gem_gym' + +describe Reality do + + it "should tell me the world view" do + Reality.new("neutral").worldview.should eq "You see the world as neutral..." + end + +end From bc51d1f9e771222142c0eb86fe049ed35ff1cc73 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 27 Feb 2014 16:18:17 -0800 Subject: [PATCH 16/20] Worked through cool_game in class exercise. --- week7/exercises/features/cool_game.feature | 13 +++++++++ .../features/step_definitions/cool_game.rb | 23 ++++++++++++++++ .../step_definitions/cool_game_steps.rb | 27 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 week7/exercises/features/cool_game.feature create mode 100644 week7/exercises/features/step_definitions/cool_game.rb create mode 100644 week7/exercises/features/step_definitions/cool_game_steps.rb diff --git a/week7/exercises/features/cool_game.feature b/week7/exercises/features/cool_game.feature new file mode 100644 index 0000000..9d395af --- /dev/null +++ b/week7/exercises/features/cool_game.feature @@ -0,0 +1,13 @@ +Feature: This is a really cool game. + +Scenario: Kristian always wins the game + Given "Kristian" is logged in + When he clicks move + Then he wins the game + And he sees the text "You Won!" + +Scenario: Bethany always loses the game + Given "Bethany" is logged in + When she clicks move + Then she loses the game + And she sees the text "You Lost!" \ No newline at end of file diff --git a/week7/exercises/features/step_definitions/cool_game.rb b/week7/exercises/features/step_definitions/cool_game.rb new file mode 100644 index 0000000..7bdf4a2 --- /dev/null +++ b/week7/exercises/features/step_definitions/cool_game.rb @@ -0,0 +1,23 @@ +class CoolGame + + def initialize name + @player = name + end + + def move + if @player == "Kristian" + @won = true + else + @won = false + end + end + + def won? + @won + end + + def output + "You #{won? ? 'Won' : 'Lost'}!" + end + +end \ No newline at end of file diff --git a/week7/exercises/features/step_definitions/cool_game_steps.rb b/week7/exercises/features/step_definitions/cool_game_steps.rb new file mode 100644 index 0000000..07ea1d4 --- /dev/null +++ b/week7/exercises/features/step_definitions/cool_game_steps.rb @@ -0,0 +1,27 @@ +Given(/^"(.*?)" is logged in$/) do |name| + @game = CoolGame.new(name) +end + +When(/^he clicks move$/) do + @game.move +end + +Then(/^he wins the game$/) do + @game.won?.should be_true +end + +Then(/^he sees the text "(.*?)"$/) do |arg1| + @game.output.should eq arg1 +end + +When(/^she clicks move$/) do + @game.move +end + +Then(/^she loses the game$/) do + @game.won?.should be_false +end + +Then(/^she sees the text "(.*?)"$/) do |arg1| + @game.output.should eq arg1 +end \ No newline at end of file From e72a183780b8f456bfcdb927a98a5fd871fcb91e Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 27 Feb 2014 16:41:24 -0800 Subject: [PATCH 17/20] Still working through the in class exercises from 02202014 --- week7/exercises/features/converter.feature | 4 ++-- .../features/step_definitions/converter.rb | 15 +++++++++++++++ .../features/step_definitions/converter_steps.rb | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 week7/exercises/features/step_definitions/converter.rb create mode 100644 week7/exercises/features/step_definitions/converter_steps.rb diff --git a/week7/exercises/features/converter.feature b/week7/exercises/features/converter.feature index 5e262a8..372bc41 100644 --- a/week7/exercises/features/converter.feature +++ b/week7/exercises/features/converter.feature @@ -5,13 +5,13 @@ Feature: Converting metric Scenario: Given I have entered 32 into the converter - And I set the type to Fahrenheit + And I set the type to "Fahrenheit" When I press convert Then the result returned should be 0.0 Scenario: Given I have entered 75 into the converter - And I set the type to Fahrenheit + And I set the type to "Fahrenheit" When I press convert Then the result returned should be 23.9 diff --git a/week7/exercises/features/step_definitions/converter.rb b/week7/exercises/features/step_definitions/converter.rb new file mode 100644 index 0000000..e56f4ed --- /dev/null +++ b/week7/exercises/features/step_definitions/converter.rb @@ -0,0 +1,15 @@ +class Converter + attr_accessor :type + def initialize value + @value = value.to_f + end + + def convert + send "#{@type}_converter" + end + + def Fahrenheit_converter + (@value - 32.0 * (5.0/9.0)).round(1) + end + +end diff --git a/week7/exercises/features/step_definitions/converter_steps.rb b/week7/exercises/features/step_definitions/converter_steps.rb new file mode 100644 index 0000000..9b43a88 --- /dev/null +++ b/week7/exercises/features/step_definitions/converter_steps.rb @@ -0,0 +1,15 @@ +Given(/^I have entered (\d+) into the converter$/) do |arg1| + @converter = Converter.new arg1 +end + +Given(/^I set the type to "(.*?)"$/) do |type| + @converter.type = type +end + +When(/^I press convert$/) do + @result = @converter.convert +end + +Then(/^the result returned should be (\d+)\.(\d+)$/) do |arg1, arg2| + @result.should eq "#{arg1}.#{arg2}".float +end \ No newline at end of file From e0ace39e1d1d22fdd409fa4c3ad45dc8398fb35b Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 13 Mar 2014 09:31:23 -0700 Subject: [PATCH 18/20] Progress so far on TicTacToe: first scenario is passing and I have changed initialize to take an argument. I think I need to change current_player to call the randomizer only when the game first starts, otherwise it takes as it's argument the current player and then sets the next person as current player, something like that, lol --- .../step_definitions/tic-tac-toe-steps.rb | 10 ++--- .../features/step_definitions/tic-tac-toe.rb | 37 +++++++++++++++++++ week7/homework/features/tic-tac-toe.feature | 8 ++-- 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 week7/homework/features/step_definitions/tic-tac-toe.rb diff --git a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb index a3287c1..6a8bdc5 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb @@ -17,20 +17,20 @@ end Then /^who is X and who is O$/ do - TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol + TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol # This does not seem right, wouldn't that be referencing a module? end Given /^I have a started Tic\-Tac\-Toe game$/ do @game = TicTacToe.new(:player) - @game.player = "Renee" + @game.player = "Kody" end Given /^it is my turn$/ do - @game.current_player.should eq "Renee" + @game.current_player.should eq "Kody" end -Given /^the computer knows my name is Renee$/ do - @game.player.should eq "Renee" +Given /^the computer knows my name is Kody$/ do + @game.player.should eq "Kody" end Then /^the computer prints "(.*?)"$/ do |arg1| diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb new file mode 100644 index 0000000..5c99737 --- /dev/null +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -0,0 +1,37 @@ +def dice(sides=6) + rand(1..sides) +end + +class TicTacToe + + attr_accessor :player, :current_player, :player_symbol, :computer_symbol + + SYMBOLS = [:X, :O] + + def initialize(player="Bob") + @player = player + end + + def welcome_player + "Welcome #{@player}" + end + + def current_player + player_roll = 0 + computer_roll = 0 + while player_roll == computer_roll + player_roll = dice + computer_roll = dice + end + if player_roll > computer_roll + @player_symbol = :X + @computer_symbol = :O + return "Kody" + else + @player_symbol = :O + @computer_symbol = :X + return "Computer" + end + end + +end \ No newline at end of file diff --git a/week7/homework/features/tic-tac-toe.feature b/week7/homework/features/tic-tac-toe.feature index 6f3134d..eeee082 100644 --- a/week7/homework/features/tic-tac-toe.feature +++ b/week7/homework/features/tic-tac-toe.feature @@ -5,16 +5,16 @@ Feature: Tic-Tac-Toe Game Scenario: Begin Game Given I start a new Tic-Tac-Toe game - When I enter my name Renee - Then the computer welcomes me to the game with "Welcome Renee" + When I enter my name Kody + Then the computer welcomes me to the game with "Welcome Kody" And randomly chooses who goes first And who is X and who is O Scenario: My Turn Given I have a started Tic-Tac-Toe game And it is my turn - And the computer knows my name is Renee - Then the computer prints "Renee's Move:" + And the computer knows my name is Kody + Then the computer prints "Kody's Move:" And waits for my input of "B2" Scenario: Computer's Turn From 2be722596592abace96ab3dff8d54ca9f0585a7e Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 13 Mar 2014 09:46:00 -0700 Subject: [PATCH 19/20] Both first and second scenario's passing now. --- .../step_definitions/tic-tac-toe-steps.rb | 2 +- .../features/step_definitions/tic-tac-toe.rb | 32 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb index 6a8bdc5..bb3c8b8 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb @@ -35,7 +35,7 @@ Then /^the computer prints "(.*?)"$/ do |arg1| @game.should_receive(:puts).with(arg1) - @game.indicate_palyer_turn + @game.indicate_player_turn end Then /^waits for my input of "(.*?)"$/ do |arg1| diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb index 5c99737..9c0df85 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -4,34 +4,42 @@ def dice(sides=6) class TicTacToe - attr_accessor :player, :current_player, :player_symbol, :computer_symbol + attr_accessor :player, :HAL, :current_player, :player_symbol, :computer_symbol SYMBOLS = [:X, :O] - def initialize(player="Bob") - @player = player - end - - def welcome_player - "Welcome #{@player}" - end - - def current_player + def initialize(player="Kody") + @player = "Kody" + @HAL = "Computer" + # now we determine who goes first player_roll = 0 computer_roll = 0 while player_roll == computer_roll player_roll = dice computer_roll = dice end + # now we assign symbols to each player if player_roll > computer_roll @player_symbol = :X @computer_symbol = :O - return "Kody" + @current_player = "#{@player}" else @player_symbol = :O @computer_symbol = :X - return "Computer" + @current_player = "#{@HAL}" end end + + def welcome_player + "Welcome #{@player}" + end + + def indicate_player_turn + puts "#{@player}'s Move:" + end + + def get_player_move + STDIN.gets.chomp.upcase + end end \ No newline at end of file From 658d3882001171f9348637ba0173def3655044a7 Mon Sep 17 00:00:00 2001 From: kodywilson Date: Thu, 13 Mar 2014 16:31:25 -0700 Subject: [PATCH 20/20] What I have so far for tictactoe. --- .../step_definitions/tic-tac-toe-steps.rb | 8 +- .../features/step_definitions/tic-tac-toe.rb | 90 +++++++++++++++---- 2 files changed, 75 insertions(+), 23 deletions(-) diff --git a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb index bb3c8b8..0a31039 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe-steps.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe-steps.rb @@ -17,7 +17,7 @@ end Then /^who is X and who is O$/ do - TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol # This does not seem right, wouldn't that be referencing a module? + TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol end Given /^I have a started Tic\-Tac\-Toe game$/ do @@ -44,7 +44,7 @@ end Given /^it is the computer's turn$/ do - @game = TicTacToe.new(:computer, :O) + @game = TicTacToe.new(:computer, :X) @game.current_player.should eq "Computer" end @@ -59,11 +59,11 @@ end Then /^the board should have an X on it$/ do - @game.current_state.should include 'X' + @game.current_state.has_value?("X").should eq true end Given /^I am playing X$/ do - @game = TicTacToe.new(:computer, :X) + @game = TicTacToe.new(:player, :X) # why would this be :computer, :x if the player is playing X? @game.player_symbol.should eq :X end diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb index 9c0df85..0b0da66 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -8,25 +8,49 @@ class TicTacToe SYMBOLS = [:X, :O] - def initialize(player="Kody") - @player = "Kody" - @HAL = "Computer" - # now we determine who goes first - player_roll = 0 - computer_roll = 0 - while player_roll == computer_roll - player_roll = dice - computer_roll = dice +# @possible_moves = ['A1', 'A2', 'A3','B1', 'B2', 'B3', 'C1', 'C2', 'C3'] + + @game_board = { + 'A1' => 'open', 'A2' => 'open', 'A3' => 'open', + 'B1' => 'open', 'B2' => 'open', 'B3' => 'open', + 'C1' => 'open', 'C2' => 'open', 'C3' => 'open' + } + + @possible_moves = @game_board.keys + + @current_state = @game_board + + def initialize(current_player="Default", n=:Z) + if current_player != "Default" + current_player = "Kody" if current_player == :player + @player_symbol = :X if n == :Z + current_player = "Computer" if current_player == :computer + @current_player = current_player end - # now we assign symbols to each player - if player_roll > computer_roll - @player_symbol = :X - @computer_symbol = :O - @current_player = "#{@player}" - else - @player_symbol = :O + if n != :Z @computer_symbol = :X - @current_player = "#{@HAL}" + @player_symbol = :X + end + @player = "Kody" + @HAL = "Computer" + # now we determine who gets to play as X and who plays as O + if current_player == "Default" + player_roll = 0 + computer_roll = 0 + while player_roll == computer_roll # roll until we have different numbers so we can compare + player_roll = dice + computer_roll = dice + end + # now we assign symbols to each player + if player_roll > computer_roll + @player_symbol = :X + @computer_symbol = :O + @current_player = "#{@player}" + else + @player_symbol = :O + @computer_symbol = :X + @current_player = "#{@HAL}" + end end end @@ -37,9 +61,37 @@ def welcome_player def indicate_player_turn puts "#{@player}'s Move:" end - + def get_player_move - STDIN.gets.chomp.upcase + player_move = STDIN.gets.chomp.upcase + @game_board["#{player_move}"] = :X.to_s + player_move end + def open_spots + @game_board + end + + def computer_move + # here i will randomly choose a number from 1 - 9 and then test if that spot is open + # obviously this is not a good way to play tic tac toe! The computer should have some AI! + spot_to_roll = ['A1', 'A2', 'A3','B1', 'B2', 'B3', 'C1', 'C2', 'C3'] + move = false +# while move == false +# random_spot = dice(9) - 1 +# check_spot = spot_to_roll[random_spot] +# if check_spot == "open" +# open_spots[check_spot] = @computer_symbol +# move == true +# end +# end + check_spot = "B1" + end + +# def current_state +# @current_state = @game_board +# end + +#load_info.each do |attribute, value| + end \ No newline at end of file