From 2bb57c1a3bc5f5da1fe73b5af3256492f633d7ac Mon Sep 17 00:00:00 2001 From: A J Casper Date: Thu, 16 Oct 2014 17:05:29 -0700 Subject: [PATCH 1/7] homework added? --- HW1.rtf | Bin 0 -> 1052 bytes HW2.rtf | Bin 0 -> 1226 bytes simon_says.rb | 25 +++++++++++++++++++++++++ strings_and_rspec_spec.rb | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 HW1.rtf create mode 100644 HW2.rtf create mode 100644 simon_says.rb create mode 100644 strings_and_rspec_spec.rb diff --git a/HW1.rtf b/HW1.rtf new file mode 100644 index 0000000000000000000000000000000000000000..719eae7b25a624bfc564f28fb088362a8304b0bd GIT binary patch literal 1052 zcmZ`&O>Yx15anE{|6%B*fJ(HxX##BzRp|u|2qX|(e3|UdCT_j<%HuRtRsK8Uk0rSv zt*lvlX5O3k>=)%jUn{h%)6$OXx>+=;qrR`=YS6ChYCeBay|W>#j0BbHtv0G}H|Uu{ z1@~z5%Ill`{`BNUy;EzlUt_Wj$-;Th!IfUOj2rJ!;!ss%=}V5q+l^ zo2pW5nh#4^hph>D31_Njo z9B>KqHXq$h|LIWZj-Hrozy#oWKnNQ_pXK!Cs1rODzNOWHK6(O+gAB4|>L55^(U*j8 z@BENk%jPP|(~~FLN>)^0K&!{CL9w9#&JTcLL(u8I6i9X05!u5;sRKeAwJns2ybuYc zF&K6_1~OL4o55WU^7v^__qxp-`I!R^Af$_ETv%NmSYfee(i2)|Oz}tLi`NcYah-*L zSU`U?2f!mEK(gX!+1x@atGy^NnZ73i(Ufs5!lq_lpcOyGuB0)F%JHI12E%7uFk$Qh7Dz7Ct$<pv#R_D~c$&n(ZAU1#~{Yz9*VXpGx&5?$b7h!=;r#gUH0EIwq`@{nKs1+QXix&QzG literal 0 HcmV?d00001 diff --git a/HW2.rtf b/HW2.rtf new file mode 100644 index 0000000000000000000000000000000000000000..7ca5c55ed2676f033592e214f41c5d7aeacb4303 GIT binary patch literal 1226 zcmZ`(O>Yx15anEn|1f7%qU^Q>(H^Q2f!aePR6q!6FSF~}tf^y1wl`^1^}q9MZ_@%o ziX6wgp7$|t^3eF$R}I^s^U`frRee@BO8S1DR>O8x%}-7qn%>zMTZ7HK>8&7&XVvzJzB0~NUXw)4l2WtNwkt` zsZuFee$96xx zbqvtbD;*C4O92>~GZSd#-MB$RdK@WO-FX)Rr6lSNig$)XkfKZe!kkLQ1OkmE62jd; zYl(wX1iPlj4?rk#!h$Qq>ffIZ1Qonf?WZk{g5gd8u(8%~`~n-tLp#f z9Z;V7y^@HO0SM>=oY{B>kJgj?pGX9Zw=T};dq`#eEIlbI@#(qKm=KOKF*|#1#DBxT w%>60xr$sXFALk)sa-Y!W{R@lBHb(< Date: Thu, 16 Oct 2014 19:38:20 -0700 Subject: [PATCH 2/7] hello --- simon_says.rb | 2 +- simon_says_spec.rb | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 simon_says_spec.rb diff --git a/simon_says.rb b/simon_says.rb index 0508fb0..b24e57d 100644 --- a/simon_says.rb +++ b/simon_says.rb @@ -4,7 +4,7 @@ def echo(str) end def shout(str) - str.upcase + str.upcased end def repeat(str, n = 2) diff --git a/simon_says_spec.rb b/simon_says_spec.rb new file mode 100644 index 0000000..1f84258 --- /dev/null +++ b/simon_says_spec.rb @@ -0,0 +1,48 @@ +# Hint: require needs to be able to find this file to load it +require_relative "simon_says.rb" +#require_relative '../../spec_helper' + +describe SimonSays do + include SimonSays # Hint: Inclusion is different than SimonSays.new (read about modules) + + # Hint: We are just calling methods, we are not passing a message to a SimonSays object. + it "should echo hello" do + echo("hello").should == "hello" + end + + it "should echo bye" do + echo("bye").should == "bye" + end + + it "should shout hello" do + shout("hello").should == "HELLO" + end + + it "should shout multiple words" do + shout("hello world").should == "HELLO WORLD" + end + + it "should repeat" do + repeat("hello").should == "hello hello" + end + + it "should repeat a number of times" do + repeat("hello", 3).should == "hello hello hello" + end + + it "should return the first letter" do + start_of_word("hello", 1).should == "h" + end + + it "should return the first two letters" do + start_of_word("Bob", 2).should == "Bo" + end + + it "should tell us the first word of 'Hello World' is 'Hello'" do + first_word("Hello World").should == "Hello" + end + + it "should tell us the first word of 'oh dear' is 'oh'" do + first_word("oh dear").should == "oh" + end +end From 93e271a9b9d68c93be5784cc87796ded0e973d04 Mon Sep 17 00:00:00 2001 From: A J Casper Date: Wed, 29 Oct 2014 13:28:57 -0700 Subject: [PATCH 3/7] 'commiting?' --- HW3.rtf | Bin 0 -> 1137 bytes calculator.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 HW3.rtf create mode 100644 calculator.rb diff --git a/HW3.rtf b/HW3.rtf new file mode 100644 index 0000000000000000000000000000000000000000..3b520ec6eb0591ccf7f29fa3619d70f9e7525daf GIT binary patch literal 1137 zcmZWp(Q4c<5bSdx|FDm3X%E}UB{X>mX=rJog^~nH!7poTZHvf~k>p%WxPR}+cJ3Yu zhq2_<%REykr~n{HTXEFSbRgq-nDBG;G^EJ3D(R8)svz3|_LbvD%bP-LVf6 zGrD7=E3dEj`_q$`@_pHg70=Om`Wc!iN=Mpm&ht%y-!{*#_vN#e-IKQJyd3Mi9N4Qe zaFJzYFvaBsp8aTIUMBWWGhrwS`elTJ(7mv_qIBr=gg(+;$3qlP7xWO>DnQZWG)OoU z+)HAk&&JhH$KBUsm%wXB!=AqU9lV5~o&CQG?2jF&$7-S<5H)fuS5$G(HO0h6Z^P7A z&V+X#=$XCd%3u?Es0JQ{#T9gsm2c>G$B{H@XgPVae7Pmdy-=LLDzQ;FIw2iUXHXzc z;Q+l^juuDI2(d~xjd-!OP$h9EVh>z128g5Awq1!I<^`C%P>*wFLV4@mIG~1HLn&^q zVRcy4r9wogpS2n>072A-Zr5f=L%LqIhq3NZ**M>GguPUak=X1~3toEGHX#ZHG`_ZS zc5H>IO3BTVJGUd{=sVSH4CKvU4#q8Yv!%^w>zQiy(IpQs%-Ra_U!g867 z6AWV7+%Ise+--6hQPa+i=xYM$hzsV|3n9k~vC8@i3}je$iKiAHk==1FXy6E~NOPwn PO3?B$VJjW}9p3x{r?iM_ literal 0 HcmV?d00001 diff --git a/calculator.rb b/calculator.rb new file mode 100644 index 0000000..4775e73 --- /dev/null +++ b/calculator.rb @@ -0,0 +1,26 @@ +class Calculator + def sum(arr) + answer = 0 + arr.each{|i| answer += i} + answer + end + + def multiply(x, y = 0) + answer = x * y + answer = x.inject(:*) if x.is_a?Array + answer + end + + def pow(x, y) + answer = 1 + y.times{answer *= x} + answer + end + + def fac(x) + return 1 if x == 0 + (1..x).inject(:*) + end +end + + From e3814253b5d9d135b06cfc5a64a8b4408a922a66 Mon Sep 17 00:00:00 2001 From: A J Casper Date: Mon, 3 Nov 2014 15:17:13 -0800 Subject: [PATCH 4/7] 'hw_week4' --- HW4.rtf | Bin 0 -> 1294 bytes worker.rb | 10 ++++++++++ worker_spec.rb | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 HW4.rtf create mode 100644 worker.rb create mode 100644 worker_spec.rb diff --git a/HW4.rtf b/HW4.rtf new file mode 100644 index 0000000000000000000000000000000000000000..bc6b00971ac5fa28d5018a1f09525edad688f8a0 GIT binary patch literal 1294 zcmZ`(TW`}a6y_Oe|KZS=0YX`ltsvG1#C;RDX+oNiEFsrEY0O+Z@`X~B{CAG+bPNzu zWwp+^e7AJRT<99cjaT^)!>VcLEtA-FbviXStEN6a-m%V_5SE(0)T}c~vrhEfc?>nY z$FtHhuztii`SR$ z&p*C{Ss%i1dUWKdymE25?W|j2MaR)>9H~`H=XKbzsF~;*_<#90j(g+)0|*|3xVE)GK6={gR%xZ z8Gw?ma$nw1l?`pdu(44~*xCp-iv_bY)Y`(8bz0t=<*^w82(C4aT5rFW$}0Q_6WRo% zvICm?hkraid<2L5@By&h&+aF56`A4xTENBv=eUBao(E9Ggc!b34h3P~7JixTW_nIZ zik^@V%V~e|_U{fF#EZCDA)u@)LtWgbQrPrL^dKnnoZJVy{6_oIZo)uB$(;m4kTF@u zl%_Q|YKXdA*bd}`QIYyIb%RjE9MB~L_M!{BrcMc()=%1>{3gpya$g_iEhd&49+GlSu(2dN+RXU+vq4ABw8da8x?xWgg}?*Pa5wv z@R5`uLfO^g&ipsv^iurSjvEgNOR5XpU+)v0erHppU8kjfK%qK%U(*X7`3ehBTFfbR hR;TE>NWrBUDb&S~TViGwlf_o Date: Wed, 10 Dec 2014 17:35:00 -0800 Subject: [PATCH 5/7] realised I hadn't turned everything in just yet --- HW7.rtf | Bin 0 -> 1798 bytes pirate/features/pirate.feature | 12 +++++++++++ pirate/features/step_defintions/pirate.rb | 12 +++++++++++ .../features/step_defintions/pirate_steps.rb | 19 ++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 HW7.rtf create mode 100644 pirate/features/pirate.feature create mode 100644 pirate/features/step_defintions/pirate.rb create mode 100644 pirate/features/step_defintions/pirate_steps.rb diff --git a/HW7.rtf b/HW7.rtf new file mode 100644 index 0000000000000000000000000000000000000000..83ceb977ce07648c1df6dd2680262cdf609ef4f7 GIT binary patch literal 1798 zcma)7O^X{x5Y5@(|4_Gu;0S4UHzD?6an^z4VB#bTxeS=rbd9F6t?r?_N3&wt|L)fx zvZQrl3}VoWjCwk<>h1BI~(KL;LEb@ zt(dm&2IT|CCEY3`YcFq}o?gCqY`mJiQNnWG#`d7gwuAgU|J9`R1wJ3D5Up z^;J7{t9Ddgw?Q?_WgATM(~o#=Clgm~LjO4fhNhtphE-ttihm;;=t4y6$1UDf^>hZ|K%>yJV-Yruud7n8t-fo zYMuRo9|X)$LCK8-pf#&NqnDkyDVY5s3Y4tNlzKN=y`bM?rdc@>;E_a)M+qo80v8}; zVrm?XbSepvE_a^s{RoZbi_Iz(7TVd1NXp=v-cu&JC^|Gp`5@D;g7%l9Q)A{TEYwTV zQSbZ>)Mn50&e7ihG#tU86dcINj;p?RQ12vL($~^tt=b|_L4b5fq{`dH=OhY;0scFP zi$3fjAqTb*3Tg+jW2u3(cr*p4XZ?~G*z^m!8vu(>0ZN|ul5UmZGRc5W&TcZA_HIfA zA6&_ZyrJJW(aF=aTX6@WY7DvGKST^*g0BDM5A`j?>A9B0mBP#RnPpB#jwVnbBvS~*SzD&zV; zSq}F<@=h5fsCLP()m(3@gDOxmSIu7Rj)OX$D6<;uRkeW%ul|EovdPzSoRpEID)8F>p>u8m4C#4;-Ixcr^2Ji!Iz1UakU6jQS&C`Q?2B)YGL}}kypC#XuD_u* zNBbY=TP3fY4aH}HpZ|~r3c+=P8nGF$BOwF!a+Gc|%2Od!3&YYo&0P>7v5|XByd^%_ aGZ@iGgEJa-ea0r#`pT;M@`=B!?>+(j)PQ&Z literal 0 HcmV?d00001 diff --git a/pirate/features/pirate.feature b/pirate/features/pirate.feature new file mode 100644 index 0000000..7c66eb0 --- /dev/null +++ b/pirate/features/pirate.feature @@ -0,0 +1,12 @@ +# language: en-pirate + +Ahoy matey!: Pirate Speak + I would like help to talk like a pirate + +Heave to: The mighty speaking pirate + Gangway! I have a PirateTranslator + Blimey! I say 'Hello Friend' + Aye I hit translate + Let go and haul it prints out 'Ahoy Matey' + Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!' + diff --git a/pirate/features/step_defintions/pirate.rb b/pirate/features/step_defintions/pirate.rb new file mode 100644 index 0000000..403f888 --- /dev/null +++ b/pirate/features/step_defintions/pirate.rb @@ -0,0 +1,12 @@ +class PirateTranslator + DICTIONARY = {"Hello Friend" => "Ahoy Matey"} + + def say(str) + @phrase = str + DICTIONARY[@phrase] + end + + def translate + say(@phrase) + "\n Shiber Me Timbers You Scurvey Dogs!!" + end +end diff --git a/pirate/features/step_defintions/pirate_steps.rb b/pirate/features/step_defintions/pirate_steps.rb new file mode 100644 index 0000000..1eb2ef7 --- /dev/null +++ b/pirate/features/step_defintions/pirate_steps.rb @@ -0,0 +1,19 @@ +Gangway /^I have a (\w+)$/ do |arg| + @translator = Kernel.const_get(arg).new +end + +Blimey /^I (\w+) '(.+)'$/ do |method, arg| + @translator.send(method, arg) +end + +Blimey /^I hit (\w+)$/ do |arg| + @result = @translator.send(arg) +end + +Letgoandhaul /^it prints out '(.+)'$/ do |arg| + @result.split("\n ").first.should == arg +end + +Letgoandhaul /^it also prints '(.+)'$/ do |arg| + @result.split("\n ").last.should == arg +end From e5aebef14f3b081e3564e0f3fca741acdb81dc9a Mon Sep 17 00:00:00 2001 From: A J Casper Date: Wed, 10 Dec 2014 17:43:51 -0800 Subject: [PATCH 6/7] working this time? --- HW7_.rtf | Bin 0 -> 1798 bytes pirate_/features/pirate.feature | 12 +++++++++++ pirate_/features/step_defintions/pirate.rb | 12 +++++++++++ .../features/step_defintions/pirate_steps.rb | 19 ++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 HW7_.rtf create mode 100644 pirate_/features/pirate.feature create mode 100644 pirate_/features/step_defintions/pirate.rb create mode 100644 pirate_/features/step_defintions/pirate_steps.rb diff --git a/HW7_.rtf b/HW7_.rtf new file mode 100644 index 0000000000000000000000000000000000000000..83ceb977ce07648c1df6dd2680262cdf609ef4f7 GIT binary patch literal 1798 zcma)7O^X{x5Y5@(|4_Gu;0S4UHzD?6an^z4VB#bTxeS=rbd9F6t?r?_N3&wt|L)fx zvZQrl3}VoWjCwk<>h1BI~(KL;LEb@ zt(dm&2IT|CCEY3`YcFq}o?gCqY`mJiQNnWG#`d7gwuAgU|J9`R1wJ3D5Up z^;J7{t9Ddgw?Q?_WgATM(~o#=Clgm~LjO4fhNhtphE-ttihm;;=t4y6$1UDf^>hZ|K%>yJV-Yruud7n8t-fo zYMuRo9|X)$LCK8-pf#&NqnDkyDVY5s3Y4tNlzKN=y`bM?rdc@>;E_a)M+qo80v8}; zVrm?XbSepvE_a^s{RoZbi_Iz(7TVd1NXp=v-cu&JC^|Gp`5@D;g7%l9Q)A{TEYwTV zQSbZ>)Mn50&e7ihG#tU86dcINj;p?RQ12vL($~^tt=b|_L4b5fq{`dH=OhY;0scFP zi$3fjAqTb*3Tg+jW2u3(cr*p4XZ?~G*z^m!8vu(>0ZN|ul5UmZGRc5W&TcZA_HIfA zA6&_ZyrJJW(aF=aTX6@WY7DvGKST^*g0BDM5A`j?>A9B0mBP#RnPpB#jwVnbBvS~*SzD&zV; zSq}F<@=h5fsCLP()m(3@gDOxmSIu7Rj)OX$D6<;uRkeW%ul|EovdPzSoRpEID)8F>p>u8m4C#4;-Ixcr^2Ji!Iz1UakU6jQS&C`Q?2B)YGL}}kypC#XuD_u* zNBbY=TP3fY4aH}HpZ|~r3c+=P8nGF$BOwF!a+Gc|%2Od!3&YYo&0P>7v5|XByd^%_ aGZ@iGgEJa-ea0r#`pT;M@`=B!?>+(j)PQ&Z literal 0 HcmV?d00001 diff --git a/pirate_/features/pirate.feature b/pirate_/features/pirate.feature new file mode 100644 index 0000000..7c66eb0 --- /dev/null +++ b/pirate_/features/pirate.feature @@ -0,0 +1,12 @@ +# language: en-pirate + +Ahoy matey!: Pirate Speak + I would like help to talk like a pirate + +Heave to: The mighty speaking pirate + Gangway! I have a PirateTranslator + Blimey! I say 'Hello Friend' + Aye I hit translate + Let go and haul it prints out 'Ahoy Matey' + Avast! it also prints 'Shiber Me Timbers You Scurvey Dogs!!' + diff --git a/pirate_/features/step_defintions/pirate.rb b/pirate_/features/step_defintions/pirate.rb new file mode 100644 index 0000000..403f888 --- /dev/null +++ b/pirate_/features/step_defintions/pirate.rb @@ -0,0 +1,12 @@ +class PirateTranslator + DICTIONARY = {"Hello Friend" => "Ahoy Matey"} + + def say(str) + @phrase = str + DICTIONARY[@phrase] + end + + def translate + say(@phrase) + "\n Shiber Me Timbers You Scurvey Dogs!!" + end +end diff --git a/pirate_/features/step_defintions/pirate_steps.rb b/pirate_/features/step_defintions/pirate_steps.rb new file mode 100644 index 0000000..1eb2ef7 --- /dev/null +++ b/pirate_/features/step_defintions/pirate_steps.rb @@ -0,0 +1,19 @@ +Gangway /^I have a (\w+)$/ do |arg| + @translator = Kernel.const_get(arg).new +end + +Blimey /^I (\w+) '(.+)'$/ do |method, arg| + @translator.send(method, arg) +end + +Blimey /^I hit (\w+)$/ do |arg| + @result = @translator.send(arg) +end + +Letgoandhaul /^it prints out '(.+)'$/ do |arg| + @result.split("\n ").first.should == arg +end + +Letgoandhaul /^it also prints '(.+)'$/ do |arg| + @result.split("\n ").last.should == arg +end From beb99a2ac252b9642b4a978bf953fe7e4742971e Mon Sep 17 00:00:00 2001 From: A J Casper Date: Thu, 11 Dec 2014 16:53:34 -0800 Subject: [PATCH 7/7] final --- .../features/step_defintions/tic-tac-toe.rb | 124 ++++++++++++++++++ .../step_defintions/tic-tac-toe_steps.rb | 109 +++++++++++++++ tic-tac-toe/features/tic-tac-toe.feature | 58 ++++++++ 3 files changed, 291 insertions(+) create mode 100644 tic-tac-toe/features/step_defintions/tic-tac-toe.rb create mode 100644 tic-tac-toe/features/step_defintions/tic-tac-toe_steps.rb create mode 100644 tic-tac-toe/features/tic-tac-toe.feature diff --git a/tic-tac-toe/features/step_defintions/tic-tac-toe.rb b/tic-tac-toe/features/step_defintions/tic-tac-toe.rb new file mode 100644 index 0000000..94a5083 --- /dev/null +++ b/tic-tac-toe/features/step_defintions/tic-tac-toe.rb @@ -0,0 +1,124 @@ +class TicTacToe + SYMBOLS = [:X, :O] + attr_accessor :player, :playerXO, :board, :random, :comp_turn, :winning_symbol + + def initialize(player_turn = nil, playerXO = nil) + @player = player_turn.to_s.capitalize unless player_turn.nil? + @random = true if player_turn == nil + @playerXO = playerXO + @board = {:A1 => " ", :A2 => " ", :A3 => " ", + :B1 => " ", :B2 => " ", :B3 => " ", + :C1 => " ", :C2 => " ", :C3 => " "} + end + + def welcome_player + "Welcome #{@player}" + end + + def current_player + if @random == true + @random = false + [@player, "Computer"].sample + elsif @comp_turn == true + @comp_turn == false + "Computer" + else + @player + end + end + + def player_symbol + @playerXO = SYMBOLS.sample + end + + def computer_symbol + sym = SYMBOLS.clone + sym.delete(@playerXO) + sym[0] + end + + def indicate_player_turn + puts "#{@player}'s Move:" + end + + def get_player_move + gets.chomp + end + + def open_spots + open_arr = [] + @board.select{|k, v| open_arr << k if v == " "} + open_arr + end + + def computer_move + move_arr = [] + @board.select{|k, v| move_arr << k if v == " "} + move = move_arr.sample + @board[move] = "#{computer_symbol}" + @comp_turn = false + move + end + + def player_move + move = get_player_move.to_sym until open_spots.include?move + @board[move] = "#{player_symbol}" + @comp_turn = true + move + end + + def current_state + result = "" + result << "#{@board[:A1]}|#{@board[:A2]}|#{@board[:A3]}\n" + result << "-" "|" "-" "|" "-\n" + result << "#{@board[:B1]}|#{@board[:B2]}|#{@board[:B3]}\n" + result << "-" "|" "-" "|" "-\n" + result << "#{@board[:C1]}|#{@board[:C2]}|#{@board[:C3]}" + end + + def determine_winner + x_arr = [] + o_arr = [] + @board.each{|k, v| x_arr << k if v == "X"} + @board.each{|k, v| o_arr << k if v == "O"} + + x_l = [] + x_n = [] + o_l = [] + o_n = [] + x_arr.each{|i| x_l << i[0]} + x_arr.each{|i| x_n << i[1]} + o_arr.each{|i| o_l << i[0]} + o_arr.each{|i| o_n << i[1]} + + la = ["A","A","A"] + lb = ["B","B","B"] + lc = ["C","C","C"] + n1 = ["1","1","1"] + n2 = ["2","2","2"] + n3 = ["3","3","3"] + @winning_symbol = :X if ((((x_l==(la||lb||lc))&&(x_n==(n1||n2||n3)))&&(@board[:B2]==X))||((x_l.uniq.sort==["A","B","C"])||(x_n.uniq.sort==["1","2","3"]))) + @winning_symbol = :O if ((((o_l==(la||lb||lc))&&(o_n==(n1||n2||n3)))&&(@board[:B2]==X))||((o_l.uniq.sort==["A","B","C"])||(o_n.uniq.sort==["1","2","3"]))) + end + + def over? + spots_open? || player_won? || computer_won? + end + + def spots_open? + @board.each{|k, v| v.to_s.include?(" ")} + end + + def player_won? + @winning_symbol == player_symbol + end + + def computer_won? + @winning_symbol == computer_symbol + end + + def draw? + over? && !player_won? && !computer_won? + end +end + diff --git a/tic-tac-toe/features/step_defintions/tic-tac-toe_steps.rb b/tic-tac-toe/features/step_defintions/tic-tac-toe_steps.rb new file mode 100644 index 0000000..d1f5265 --- /dev/null +++ b/tic-tac-toe/features/step_defintions/tic-tac-toe_steps.rb @@ -0,0 +1,109 @@ +require 'rspec/mocks/standalone' +require 'rspec/expectations' + +Given /^I start a new Tic\-Tac\-Toe game$/ do + @game = TicTacToe.new +end +When /^I enter my name (\w+)$/ do |name| + @game.player = name +end +Then /^the computer welcomes me to the game with "(.*?)"$/ do |arg1| + @game.welcome_player.should eq arg1 +end +Then /^randomly chooses who goes first$/ do + [@game.player, "Computer"].should include @game.current_player +end +Then /^who is X and who is O$/ do + TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol +end + +Given /^I have a started Tic\-Tac\-Toe game$/ do + @game = TicTacToe.new(:player) + @game.player = "Renee" +end +Given /^it is my turn$/ do + @game.current_player.should eq "Renee" +end +Given /^the computer knows my name is Renee$/ do + @game.player.should eq "Renee" +end +Then /^the computer prints "(.*?)"$/ do |arg1| + @game.should_receive(:puts).with(arg1) + @game.indicate_player_turn +end +Then /^waits for my input of "(.*?)"$/ do |arg1| + @game.should_receive(:gets).and_return(arg1) + @game.get_player_move +end + +Given /^it is the computers turn$/ do +# @game = TicTacToe.new(:computer, :O) + @game = TicTacToe.new(:computer, :X) + @game.current_player.should eq "Computer" +end +Given /^the computer is playing X$/ do + @game.computer_symbol.should eq :X +end +Then /^the computer randomly chooses an open position for its move$/ do + open_spots = @game.open_spots + @com_move = @game.computer_move + open_spots.should include(@com_move) +end +Then /^the board should have an X on it$/ do + @game.current_state.should include 'X' +end + +Given /^I am playing X$/ do + @game = TicTacToe.new(:computer, :X) + @game.player_symbol.should eq :X +end +When /^I enter a position "(.*?)" on the board$/ do |arg1| + @old_pos = @game.board[arg1.to_sym] + @game.should_receive(:get_player_move).and_return(arg1) + @game.player_move.should eq arg1.to_sym +end +When /^"(.*?)" is not taken$/ do |arg1| + @old_pos.should eq " " +end +Then /^it is now the computers turn$/ do + @game.current_player.should eq "Computer" +end + +When /^"(.*?)" is taken$/ do |arg1| + @game.board[arg1.to_sym] = :O + @taken_spot = arg1.to_sym +end +Then /^computer should ask me for another position "(.*?)"$/ do |arg1| + @game.board[arg1.to_sym] = ' ' + @game.should_receive(:get_player_move).twice.and_return(@taken_spot, arg1) + @game.player_move.should eq arg1.to_sym +end + +When /^there are three Xs in a row$/ do + @game = TicTacToe.new(:computer, :X) + @game.board[:C1] = @game.board[:B2] = @game.board[:A3] = :X +end +Then /^I am declared the winner$/ do + @game.determine_winner + @game.player_won?.should be_truthy +end +Then /^the game ends$/ do + @game.over?.should be_truthy +end + +Given /^there are not three symbols in a row$/ do + @game.board = { + :A1 => :X, :A2 => :O, :A3 => :X, + :B1 => :X, :B2 => :O, :B3 => :X, + :C1 => :O, :C2 => :X, :C3 => :O + } + @game.determine_winner +end +When /^there are no open spaces left on the board$/ do + @game.spots_open?.should !be_truthy +end +Then /^the game is declared a draw$/ do + @game.draw?.should be_truthy +end + + diff --git a/tic-tac-toe/features/tic-tac-toe.feature b/tic-tac-toe/features/tic-tac-toe.feature new file mode 100644 index 0000000..aaae033 --- /dev/null +++ b/tic-tac-toe/features/tic-tac-toe.feature @@ -0,0 +1,58 @@ +Feature: Tic-Tac-Toe Game + As a game player I like tic-tac-toe + In order to up my skills + I would like to play agaist the computer + +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" + 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 waits for my input of "B2" + +Scenario: Computer's Turn + Given I have a started Tic-Tac-Toe game + And it is the computers turn + And the computer is playing X + Then the computer randomly chooses an open position for its move + And the board should have an X on it + +Scenario: Making Moves + Given I have a started Tic-Tac-Toe game + And it is my turn + And I am playing X + When I enter a position "A1" on the board + And "A1" is not taken + Then the board should have an X on it + And it is now the computers turn + +Scenario: Making Bad Moves + Given I have a started Tic-Tac-Toe game + And it is my turn + And I am playing X + When I enter a position "A1" on the board + And "A1" is taken + Then computer should ask me for another position "B2" + And it is now the computers turn + +Scenario: Winning the Game + Given I have a started Tic-Tac-Toe game + And I am playing X + When there are three Xs in a row + Then I am declared the winner + And the game ends + +Scenario: Game is a draw + Given I have a started Tic-Tac-Toe game + And there are not three symbols in a row + When there are no open spaces left on the board + Then the game is declared a draw + And the game ends +