From 639868a80da1b5c9e28ba246eb1dfd44306d5fbe Mon Sep 17 00:00:00 2001 From: "malloryfontenot@gmail.com" Date: Tue, 16 Oct 2012 18:22:44 -0700 Subject: [PATCH 01/11] homework week1 --- .DS_Store | Bin 0 -> 6148 bytes week1/.DS_Store | Bin 0 -> 6148 bytes week1/homework/.DS_Store | Bin 0 -> 6148 bytes week1/homework/questions.txt | 11 +++++++++++ week1/homework/strings_and_rspec_spec.rb | 13 +++++++------ 5 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 week1/.DS_Store create mode 100644 week1/homework/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dfb063e976f17854fc8858c6d9edcb187288f14c GIT binary patch literal 6148 zcmeHK&1%~~5T14HMxqV)Qt)xoZPL!iU~ADYriQHV`cD_C-TaGi+0 zP+lPqkaJ(h{bqL^Y}{UpDKldB8_mw_&$nV%OGK(Yj(3TwMC3skOFoJ}2-mZ&Ny&LC zKxNuEp+joWcZ!dbwP+M zbkZHfmr*$SV(dK3$5}fZnVL^w-banG&(bu3eeR-rgE;Sht=6W~)_$w5_gc+aT~7}V znswdUdpDc;p66E|z1MFV?~l&HAG5pr!VHxZK4K#~4j1qf#?qAI>>`QKCx`B078X$hQ8pE5Qzc%5d0*g`# z1H!;616%gB%IE*#-|zpcN%AHP2m}8W1FGEVcG{SdJ6qQ#$7ijEeuJ`bTw(D!1%^3_ f5z9w$4Qd2_%?2=VSXhJyB0mC#1}TJrf6Bmb5{O^_ literal 0 HcmV?d00001 diff --git a/week1/.DS_Store b/week1/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2a089047fd5f2539aa8af12a6b52831587bb91ef GIT binary patch literal 6148 zcmeHK!A{#i5S-d=qCk~Q@a#x9seQ&{O;aUixRxG4A-24Aw3cze3dg;*Vt9FX&K*BvxFT`oNTaOg^jF;&M^Eeu8)duAj_fz%s2v9BzOwTm z?`4f3RXv+Q-a(JDw=reddnS4(j`GeyZDuf7tS{H+y-!P@hx6WGWd-)~(wE`TbsV>L z>3o=7_`1Fw3{QU*XX=SbFmWvJG>qGGSf%;=mYm~e+D&BlI}&e;j;mS2GGG~aSqzwu zfHVEFrfp|y8L$jIg8}|Ncu+>)V4+ccI?$*i0I&+T64?Bc$T^-t-(aB;JrJQ&fjU)~ zBZkoF@OviCH&|%Y=_JhILzt0;IiUzOI_i5WoP@8@ww3|Qz$61x`nJaV|Ju{%|H&kK zXBn^z{8tQ!>S}Yffhn22wKO^2Ydz>8l!fC8jpGy;YAZ%8Z^a*>O5pd{0Qv?CjqpJ1 OkAR}VHkN_E%D@f(U5JJN literal 0 HcmV?d00001 diff --git a/week1/homework/.DS_Store b/week1/homework/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f96a5a9eba420c03135cafc3e584f811b67ea744 GIT binary patch literal 6148 zcmeHK%Sr=55Uhzg1VqSDZ*%k%@DG*{1nB7r+?6h$>7ndPMHtp@9brQ>oG72@O_w!KA0qUvz2hCwRsd4_x)< z^|yFMd%bMt^|GlMC5o=7=hU>@u?5ab&W2yT!Xxcl+|ybRH|(uhb5472P3Wz^RD5F< zRUCLlRSgLSf`MQl7zhS_k^!FClF_kYw820y5Da`Up#33Jg_UDxShfx}x;|@sD3s9F zMOl~~E62`|Ba~#RL`zNn#7LG-fA+Y_u`{%Eq%t$>_{{sqODeO|pG!DWWf*NR5DXkL zaAe)F&i_mPGQE%d!<6U+1Hr&QV;~J@H?t`}%FotspQp1nQ}3t}#dR_$v=1%;>}Vf3 eErT|mWizgF>!{*q3Ni$EbHnqc4;7 Date: Tue, 16 Oct 2012 19:36:31 -0700 Subject: [PATCH 02/11] week 1 HW --- week1/homework/strings_and_rspec_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week1/homework/strings_and_rspec_spec.rb b/week1/homework/strings_and_rspec_spec.rb index bcd48fb..50d1690 100644 --- a/week1/homework/strings_and_rspec_spec.rb +++ b/week1/homework/strings_and_rspec_spec.rb @@ -5,7 +5,7 @@ @my_string = "Renée is a fun teacher. Ruby is a really cool programming language" end it "should be able to count the charaters" do - @my_string.length + @my_string.should have(@my_string.size).characters end it "should be able to split on the . charater" do result = @my_string.split(/\s*\.\s*/) From a79b4ebad7e2d45e15ccae3251d83a09702fe616 Mon Sep 17 00:00:00 2001 From: "malloryfontenot@gmail.com" Date: Tue, 16 Oct 2012 21:08:08 -0700 Subject: [PATCH 03/11] removing unnecessary files --- .DS_Store | Bin 6148 -> 0 bytes week1/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 week1/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index dfb063e976f17854fc8858c6d9edcb187288f14c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&1%~~5T14HMxqV)Qt)xoZPL!iU~ADYriQHV`cD_C-TaGi+0 zP+lPqkaJ(h{bqL^Y}{UpDKldB8_mw_&$nV%OGK(Yj(3TwMC3skOFoJ}2-mZ&Ny&LC zKxNuEp+joWcZ!dbwP+M zbkZHfmr*$SV(dK3$5}fZnVL^w-banG&(bu3eeR-rgE;Sht=6W~)_$w5_gc+aT~7}V znswdUdpDc;p66E|z1MFV?~l&HAG5pr!VHxZK4K#~4j1qf#?qAI>>`QKCx`B078X$hQ8pE5Qzc%5d0*g`# z1H!;616%gB%IE*#-|zpcN%AHP2m}8W1FGEVcG{SdJ6qQ#$7ijEeuJ`bTw(D!1%^3_ f5z9w$4Qd2_%?2=VSXhJyB0mC#1}TJrf6Bmb5{O^_ diff --git a/week1/.DS_Store b/week1/.DS_Store deleted file mode 100644 index 2a089047fd5f2539aa8af12a6b52831587bb91ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!A{#i5S-d=qCk~Q@a#x9seQ&{O;aUixRxG4A-24Aw3cze3dg;*Vt9FX&K*BvxFT`oNTaOg^jF;&M^Eeu8)duAj_fz%s2v9BzOwTm z?`4f3RXv+Q-a(JDw=reddnS4(j`GeyZDuf7tS{H+y-!P@hx6WGWd-)~(wE`TbsV>L z>3o=7_`1Fw3{QU*XX=SbFmWvJG>qGGSf%;=mYm~e+D&BlI}&e;j;mS2GGG~aSqzwu zfHVEFrfp|y8L$jIg8}|Ncu+>)V4+ccI?$*i0I&+T64?Bc$T^-t-(aB;JrJQ&fjU)~ zBZkoF@OviCH&|%Y=_JhILzt0;IiUzOI_i5WoP@8@ww3|Qz$61x`nJaV|Ju{%|H&kK zXBn^z{8tQ!>S}Yffhn22wKO^2Ydz>8l!fC8jpGy;YAZ%8Z^a*>O5pd{0Qv?CjqpJ1 OkAR}VHkN_E%D@f(U5JJN From cdf6d8c7d8c6713b8f196a61b18f140a955c2a18 Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Mon, 22 Oct 2012 22:46:39 -0700 Subject: [PATCH 04/11] week2 homework --- week2/homework/questions.txt | 11 +++++++++++ week2/homework/simon_says.rb | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 week2/homework/simon_says.rb diff --git a/week2/homework/questions.txt b/week2/homework/questions.txt index 247547d..37587cf 100644 --- a/week2/homework/questions.txt +++ b/week2/homework/questions.txt @@ -3,7 +3,18 @@ Containers, Blocks, and Iterators Sharing Functionality: Inheritance, Modules, and Mixins 1. What is the difference between a Hash and an Array? +Both are a collection of objects that are indexed, an array is indexed with integers while a hash is indexed with any object (symbols, strings, regular expressions, etc) + 2. When would you use an Array over a Hash and vice versa? +Use a hash when you want to obtain an object by referencing an object (example, items in a purse: lipstick, wallet, etc) while an array is an ordered collection that is referenced linearly (0, 1, 2, 3) + 3. What is a module? Enumerable is a built in Ruby module, what is it? +A module is a way of grouping together methods, classes, and constants. They provide a namespace, prevent name clashes, and supports the mixin facility. + +Enumerable: applies a function or operation to all items, since it runs through all objects you are able to use min/max/sort. Seems to be a simple way to evaluate all items instead of running through a loop. + 4. Can you inherit more than one thing in Ruby? How could you get around this problem? +No, but you can use mixin modules to include subsets of information + 5. What is the difference between a Module and a Class? +A module contains methods and logic but does not retain information. A class contains objects while a module is not an object. diff --git a/week2/homework/simon_says.rb b/week2/homework/simon_says.rb new file mode 100644 index 0000000..4487bd1 --- /dev/null +++ b/week2/homework/simon_says.rb @@ -0,0 +1,24 @@ +module SimonSays + def echo(message) + message + end + + def shout(message) + message.upcase + end + + def repeat(message,times_repeated=2) + a = [message]*times_repeated + a.join(" ") + end + + def start_of_word(message,char=1) + b = message.split(//) + b[0...char].join + end + + def first_word(message) + c = message.split(/ /).to_a + c[0] + end +end \ No newline at end of file From 2a19f44a814771a18f23dd7d35aa3f94305e43aa Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Mon, 29 Oct 2012 22:28:16 -0700 Subject: [PATCH 05/11] week3 HW --- week3/homework/calculator_spec_hw.rb | 80 ++++++++++++++++++++++++++++ week3/homework/questions_hw3.txt | 18 +++++++ 2 files changed, 98 insertions(+) create mode 100644 week3/homework/calculator_spec_hw.rb create mode 100644 week3/homework/questions_hw3.txt diff --git a/week3/homework/calculator_spec_hw.rb b/week3/homework/calculator_spec_hw.rb new file mode 100644 index 0000000..c99af45 --- /dev/null +++ b/week3/homework/calculator_spec_hw.rb @@ -0,0 +1,80 @@ +require "#{File.dirname(__FILE__)}/calculator" + +describe Calculator do + + before do + @calculator = Calculator.new + end + + describe "#sum" do + it "computes the sum of an empty array" do + @calculator.sum([]).should == 0 + end + + it "computes the sum of an array of one number" do + @calculator.sum([7]).should == 7 + end + + it "computes the sum of an array of two numbers" do + @calculator.sum([7,11]).should == 18 + end + + it "computes the sum of an array of many numbers" do + @calculator.sum([1,3,5,7,9]).should == 25 + end + end + + # Once the above tests pass, + # write tests and code for the following: + + describe "#mult" do + it "multiplies two numbers" do + @calculator.mult(7,2).should == 14 + end + + it "multiplies two numbers, same value" do + @calculator.mult(2,2).should == 4 + end + end + + describe "#multa" do + it "multiplies an array of numbers" do + @calculator.multa([1,2,3]).should == 6 + end + + it "multiplies an array of numbers" do + @calculator.multa([5,7,10]).should == 350 + end + end + + describe "#raiseby" do + it "raises one number to the power of another number" do + @calculator.raiseby(5,2).should == 25 + end + + it "raises one number to the power of another number" do + @calculator.raiseby(3,5).should == 243 + end + end + + # http://en.wikipedia.org/wiki/Factorial + describe "#factorial" do + it "computes the factorial of 0" do + @calculator.factorial(0).should == 1 + end + + it "computes the factorial of 1" do + @calculator.factorial(1).should == 1 + end + it "computes the factorial of 2" do + @calculator.factorial(2).should == 2 + end + it "computes the factorial of 5" do + @calculator.factorial(5).should == 120 + end + it "computes the factorial of 10" do + @calculator.factorial(10).should == 3628800 + end + end + +end diff --git a/week3/homework/questions_hw3.txt b/week3/homework/questions_hw3.txt new file mode 100644 index 0000000..5a103c7 --- /dev/null +++ b/week3/homework/questions_hw3.txt @@ -0,0 +1,18 @@ +1. What is a symbol? +A symbol is an identifier corresponding to a string of characters, often a name. + +2. What is the difference between a symbol and a string? +A symbol is an unchangable string. + +3. What is a block and how do I call a block? +A block is a bit of code between either braces or do/end, blocks are not objects. +A block can be called by using call, yield or []. +However, you can also call it by name.(arg) which maps to name.call(arg) + +4. How do I pass a block to a method? What is the method signature? +You pass a block to a method by listing the last parameter as a prefix with an ampersand. ex. def test(&block) +A method signature is the method name and all if its arguments. + +5. Where would you use regular expressions? +A regular expression is to identify a pattern in a string. +I imagine using regular expressions when finding data points based on unique ID format. \ No newline at end of file From dd20058e5fbad017a6ca3c111130e326fa536fe4 Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Mon, 29 Oct 2012 22:32:51 -0700 Subject: [PATCH 06/11] calc file --- week3/homework/calculator.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/week3/homework/calculator.rb b/week3/homework/calculator.rb index ede464b..8a28761 100644 --- a/week3/homework/calculator.rb +++ b/week3/homework/calculator.rb @@ -1,2 +1,28 @@ class Calculator -end \ No newline at end of file + def sum(num_array) + num_array.inject(0) do |total, value| + total + value + end + end + + def mult(x, y) + x*y + end + + def multa(num_array) + num_array.inject(1) do |total, value| + total * value + end + end + + def raiseby(x,y) + x**y + end + + def factorial(x) + (1..x).inject(1) do |total, value| + total*value + end + end +end + From 255b928fa24dfd92ad591d3fbe8bef7bb8b9669a Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Tue, 6 Nov 2012 17:24:02 -0800 Subject: [PATCH 07/11] homework --- week4/class_materials/timer.rb | 8 ++++++++ week4/exercises/odd_number.rb | 21 +++++++++++++++++++++ week4/exercises/worker.rb | 9 +++++++++ 3 files changed, 38 insertions(+) create mode 100644 week4/class_materials/timer.rb create mode 100644 week4/exercises/odd_number.rb create mode 100644 week4/exercises/worker.rb diff --git a/week4/class_materials/timer.rb b/week4/class_materials/timer.rb new file mode 100644 index 0000000..56a77ab --- /dev/null +++ b/week4/class_materials/timer.rb @@ -0,0 +1,8 @@ +class Timer + def self.time_code(&my_code) + start_time = Time.now + my_code.call + end_time = Time.now + end_time - start_time + end +end diff --git a/week4/exercises/odd_number.rb b/week4/exercises/odd_number.rb new file mode 100644 index 0000000..c9e1e9f --- /dev/null +++ b/week4/exercises/odd_number.rb @@ -0,0 +1,21 @@ +class OddNumber + attr_reader :value + + def initialize(value) + @value = value + end + + def succ + new_val = nil + if + OddNumber.new(@value + 1) + else + OddNumber.new(@value+1) + end + new_val + end + + def <==>(other) + @value <==>other.value + end +end diff --git a/week4/exercises/worker.rb b/week4/exercises/worker.rb new file mode 100644 index 0000000..e2b6b70 --- /dev/null +++ b/week4/exercises/worker.rb @@ -0,0 +1,9 @@ +class Worker + def self.work (n=1) + result = nil + n.times do + result = yield + end + result + end +end From 9428a879adb171774e84a5c02490a255aa9e7913 Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Mon, 3 Dec 2012 17:51:57 -0800 Subject: [PATCH 08/11] begining tictactoe --- .../features/step_definitions/tic-tac-toe.rb | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 week7/homework/features/step_definitions/tic-tac-toe.rb 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..4d0aa93 --- /dev/null +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -0,0 +1,59 @@ +class TicTacToe + SYMBOLS = [:X, :O] + attr_accessor :player,:p_symbol, :whos_turn, :comp, :comp_symbol, :board + + def initialize (first_player=nil, first_symb=nil) + @player = pick_first_player(first_player).to_s.capitalize + pick_player_symbol(first_symb) + @board = {":A1"=>"", ":A2"=>"",":A3"=>"", + ":B1"=>"",":B2"=>"",":B3"=>"", + ":C1"=>"",":C2"=>"",":C3"=>""} + end + + def pick_first_player(first_player) + if first_player.nil? + start = Random.new + start.rand(0..1) + if start == 0 + @whos_turn="Computer" + else + @whos_turn=@player + end + else + @whos_turn = first_player + end + end + + def pick_player_symbol(first_symbol) + if first_symbol.nil? + @p_symbol = :X + else + @p_symbol = first_symbol + end + end + + def welcome_player + "Welcome " + @player.to_s + end + + def current_player + @player + end + + def player_symbol + @p_symbol + end + + def computer_symbol + @p_symbol + end + + def indicate_palyer_turn + @player.to_s+"'s Move" + end + + def get_player_move + "And waits for my input of" + end + +end From 861459ae4c4ecc8e8651ff2f40ccf7698a056fcf Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Mon, 3 Dec 2012 21:12:20 -0800 Subject: [PATCH 09/11] progress on tictactoe --- .../features/step_definitions/tic-tac-toe.rb | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb index 4d0aa93..41ebbe1 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -1,35 +1,45 @@ class TicTacToe SYMBOLS = [:X, :O] - attr_accessor :player,:p_symbol, :whos_turn, :comp, :comp_symbol, :board + attr_accessor :player,:p_symbol, :comp, :comp_symbol,:whos_first,:board, :com_move def initialize (first_player=nil, first_symb=nil) @player = pick_first_player(first_player).to_s.capitalize pick_player_symbol(first_symb) - @board = {":A1"=>"", ":A2"=>"",":A3"=>"", - ":B1"=>"",":B2"=>"",":B3"=>"", - ":C1"=>"",":C2"=>"",":C3"=>""} + @board = {":A1"=>nil, ":A2"=>nil,":A3"=>nil, + ":B1"=>nil,":B2"=>nil,":B3"=>nil, + ":C1"=>nil,":C2"=>nil,":C3"=>nil} end def pick_first_player(first_player) if first_player.nil? - start = Random.new - start.rand(0..1) + start = rand(0..1) if start == 0 - @whos_turn="Computer" + @whos_first="Computer" else - @whos_turn=@player + @whos_first=@player end else - @whos_turn = first_player + @whos_first = first_player end end def pick_player_symbol(first_symbol) if first_symbol.nil? - @p_symbol = :X + start = rand(0..1) + if start == 0 + @p_symbol=:X + else + @p_symbol=:O + end else @p_symbol = first_symbol end + + if @p_symbol ==:X + @comp_symbol = :O + else + @comp_symbol = :X + end end def welcome_player @@ -45,7 +55,7 @@ def player_symbol end def computer_symbol - @p_symbol + @comp_symbol end def indicate_palyer_turn @@ -56,4 +66,19 @@ def get_player_move "And waits for my input of" end + def open_spots + @open_spots = @board.find_all{|space,value| value.nil?} + end + + def computer_move + random_spot = rand(0..@open_spots.count) + spot = @open_spots[random_spot] + @board[spot[0]] = @comp_symbol + spot + end + + def current_state + @board.values.map(&:to_s) + end + end From 4d56aebafc90f590a792b6ecebf47612300ea805 Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Mon, 3 Dec 2012 23:26:02 -0800 Subject: [PATCH 10/11] tictactoepassing, working on scoring --- .../features/step_definitions/tic-tac-toe.rb | 74 ++++++++++++++----- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb index 41ebbe1..44f503a 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -1,26 +1,37 @@ class TicTacToe SYMBOLS = [:X, :O] - attr_accessor :player,:p_symbol, :comp, :comp_symbol,:whos_first,:board, :com_move + attr_accessor :player,:p_symbol, :comp, :comp_symbol,:board, :player_move, :current_player, :first_player def initialize (first_player=nil, first_symb=nil) - @player = pick_first_player(first_player).to_s.capitalize + @first_player = first_player pick_player_symbol(first_symb) - @board = {":A1"=>nil, ":A2"=>nil,":A3"=>nil, - ":B1"=>nil,":B2"=>nil,":B3"=>nil, - ":C1"=>nil,":C2"=>nil,":C3"=>nil} + @board = {:A1=>" ", :A2=>" ",:A3=>" ", + :B1=>" ",:B2=>" ",:B3=>" ", + :C1=>" ",:C2=>" ",:C3=>" "} end - def pick_first_player(first_player) - if first_player.nil? + def pick_first_player + if @first_player.nil? start = rand(0..1) if start == 0 - @whos_first="Computer" + @current_player="Computer" else - @whos_first=@player + @current_player=@player end else - @whos_first = first_player + if @first_player==:player + @current_player = @player + else + @current_player = "Computer" + end + end + end + + def current_player + if @current_player.nil? + pick_first_player end + @current_player end def pick_player_symbol(first_symbol) @@ -45,10 +56,6 @@ def pick_player_symbol(first_symbol) def welcome_player "Welcome " + @player.to_s end - - def current_player - @player - end def player_symbol @p_symbol @@ -62,18 +69,15 @@ def indicate_palyer_turn @player.to_s+"'s Move" end - def get_player_move - "And waits for my input of" - end - def open_spots - @open_spots = @board.find_all{|space,value| value.nil?} + @open_spots = @board.find_all{|space,value| value==" "} end def computer_move random_spot = rand(0..@open_spots.count) spot = @open_spots[random_spot] @board[spot[0]] = @comp_symbol + @current_player=@player spot end @@ -81,4 +85,36 @@ def current_state @board.values.map(&:to_s) end + def get_player_move + gets.chomp + end + + def player_move + while move=get_player_move.to_sym do + if @board[move]==" " + @board[move]=@p_symbol + @current_player = "Computer" + break + end + end + move + end + + def determine_winner + winning = [ + [:A1,:A2,:A3], + [:B1,:B2,:B3], + [:C1,:C2,:C3], + [:A1,:B1,:C1], + [:A2,:B2,:C2], + [:A3,:B3,:C3], + [:A1,:B2,:C3], + [:C1,:B2,:A3]] +] + end + + def player_won? + + end + end From b5925823bcef4762cc470d7403e2c8c33d3e7c30 Mon Sep 17 00:00:00 2001 From: Mallory Fontenot Date: Sat, 15 Dec 2012 11:40:33 -0800 Subject: [PATCH 11/11] tic tac toe w/out scoring --- week7/homework/features/step_definitions/tic-tac-toe.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/week7/homework/features/step_definitions/tic-tac-toe.rb b/week7/homework/features/step_definitions/tic-tac-toe.rb index 44f503a..d4b125b 100644 --- a/week7/homework/features/step_definitions/tic-tac-toe.rb +++ b/week7/homework/features/step_definitions/tic-tac-toe.rb @@ -1,6 +1,6 @@ class TicTacToe SYMBOLS = [:X, :O] - attr_accessor :player,:p_symbol, :comp, :comp_symbol,:board, :player_move, :current_player, :first_player + attr_accessor :player,:p_symbol, :comp, :comp_symbol,:board, :player_move, :current_player, :first_player, :winner def initialize (first_player=nil, first_symb=nil) @first_player = first_player @@ -101,7 +101,7 @@ def player_move end def determine_winner - winning = [ + win_scenarios = [ [:A1,:A2,:A3], [:B1,:B2,:B3], [:C1,:C2,:C3], @@ -110,8 +110,11 @@ def determine_winner [:A3,:B3,:C3], [:A1,:B2,:C3], [:C1,:B2,:A3]] -] + + x_space = @board.map + end + def player_won?