Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework Four --- of chaos and beyond -- #57

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8abcc58
Working homework one
jjs0sbw Oct 6, 2014
1226384
Finishing up homework one
jjs0sbw Oct 9, 2014
9f933b9
class answers to hw
reneedv Oct 10, 2014
225c85e
new attempt to pull upstream
jjs0sbw Oct 10, 2014
5d4b26f
code from class
reneedv Oct 10, 2014
b7d1d6a
Working homework 2
jjs0sbw Oct 13, 2014
4f1f4e1
Finishing up the homework for this week.
jjs0sbw Oct 16, 2014
3a18e3f
week 1 question answers
reneedv Oct 16, 2014
75a5c1d
Merge branch 'master' into answers
reneedv Oct 17, 2014
8313f91
Finishing up the merge
jjs0sbw Oct 17, 2014
5805e88
Finished up homework questions
jjs0sbw Oct 20, 2014
6a683ae
Finishing up HW3
jjs0sbw Oct 20, 2014
d6120a7
week 3 answers
reneedv Oct 23, 2014
9280a7c
Merge remote-tracking branch 'upstream/master'
jjs0sbw Oct 24, 2014
a0602a7
Merge branch 'master' into answers
reneedv Oct 24, 2014
49e8882
week 4 work
reneedv Oct 24, 2014
b04d9b1
Working HW 4
jjs0sbw Oct 28, 2014
0938f9f
Merge branch 'master' into answers
reneedv Oct 31, 2014
b95d9db
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2014
jjs0sbw Oct 31, 2014
4157004
examples
reneedv Oct 31, 2014
7ce76a5
work from class
reneedv Oct 31, 2014
a502ac7
hw question answers
reneedv Nov 6, 2014
b6be2d1
Merge branch 'master' into answers
reneedv Nov 6, 2014
28595db
Working week 5 stuff
jjs0sbw Nov 7, 2014
8978134
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2014
jjs0sbw Nov 7, 2014
96b0ff4
Workin ganswer branch conflicts
jjs0sbw Nov 8, 2014
9fab4b2
Working answer branch conflicts
jjs0sbw Nov 8, 2014
caa2e9d
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2014
jjs0sbw Nov 14, 2014
d4d89af
Working HW 7
jjs0sbw Nov 17, 2014
5aac15c
Working HW 7
jjs0sbw Nov 17, 2014
c9328dd
Working HW 7
jjs0sbw Nov 17, 2014
459ebc8
Working HW 7 - tic-tac-toe
jjs0sbw Nov 17, 2014
ab05a5c
Working HW 7 - ttt
jjs0sbw Nov 17, 2014
a0df5d6
Working HW7
jjs0sbw Nov 20, 2014
d2fcfa6
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2014
jjs0sbw Nov 21, 2014
f818ab4
create new final directory
jjs0sbw Nov 30, 2014
f825a64
Working steps corrections
jjs0sbw Nov 30, 2014
864671f
Updated steps file
jjs0sbw Nov 30, 2014
378fb29
Working finial Ruby test
jjs0sbw Nov 30, 2014
4a7f5ab
Working Ruby final
jjs0sbw Dec 1, 2014
07f528f
Working Ruby final
jjs0sbw Dec 1, 2014
f95adea
Working Ruby final
jjs0sbw Dec 1, 2014
2c4790d
Work Ruby final
jjs0sbw Dec 1, 2014
c38d87e
Working Ruby final
jjs0sbw Dec 1, 2014
58317f4
Working Ruby final
jjs0sbw Dec 1, 2014
5131583
Working Ruby final
jjs0sbw Dec 1, 2014
3932663
Work Ruby final
jjs0sbw Dec 2, 2014
aff8b27
Ruby final passes cucumber tests
jjs0sbw Dec 2, 2014
f372b6a
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2014
jjs0sbw Dec 5, 2014
3daf5a4
Merge branch 'master' of github.com:UWE-Ruby/RubyFall2014
jjs0sbw Dec 12, 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
149 changes: 149 additions & 0 deletions final/features/step_definitions/tic-tac-toe-steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
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
expect(@game.welcome_player).to eq arg1
end

Then /^randomly chooses who goes first$/ do
#[@game.player, "Computer"].should include @game.current_player
expect([@game.player, "Computer"]).to include(@game.current_player)
end

Then /^who is X and who is O$/ do
#TicTacToe::SYMBOLS.should include @game.player_symbol, @game.computer_symbol
expect(TicTacToe::SYMBOLS).to 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"
expect(@game.current_player).to eq "Renee"
end

Given /^the computer knows my name is Renee$/ do
#@game.player.should eq "Renee"
expect(@game.player).to eq "Renee"
end

Then /^the computer prints "(.*?)"$/ do |arg1|
#@game.should_receive(:puts).with(arg1)
expect(@game).to receive(:puts).with(arg1)
@game.indicate_player_turn
end

Then /^waits for my input of "(.*?)"$/ do |arg1|
#@game.should_receive(:gets).and_return(arg1)
expect(@game).to receive(:gets).with(arg1)
#@game.get_player_move
end

Given /^it is the computer's turn$/ do #'
@game = TicTacToe.new(:computer, :X)
#@game.current_player.should eq "Computer"
expect(@game.current_player).to eq "Computer"
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)
expect(open_spots).to include(@com_move)
end

Given /^the computer is playing X$/ do
#@game.computer_symbol.should eq :X
expect(@game.computer_symbol).to eq :X
end

Then /^the board should have an X on it$/ do
#@game.current_state.should include 'X'
expect(@game.current_state).to include 'X'

end

Given /^I am playing X$/ do
@game = TicTacToe.new(:player, :X)
#@game.player_symbol.should eq :X
expect(@game.player_symbol).to 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)
expect(@game).to receive(:get_player_move).and_return(arg1)
#@game.player_move.should eq arg1.to_sym
expect(@game.player_move).to eq arg1.to_sym
end

When /^"(.*?)" is not taken$/ do |arg1|
#@old_pos.should eq " "
expect(@old_pos).to eq ""
end

Then /^it is now the computer's turn$/ do #'
#@game.current_player.should eq "Computer"
expect(@game.current_player).to eq "Computer"
end

When /^there are three X's in a row$/ do #'
@game = TicTacToe.new(:player, :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_true
expect(@game.player_won?).to be true
end

Then /^the game ends$/ do
#@game.over?.should be_true
expect(@game.over?).to be true
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_false
expect(@game.spots_open?).to be false
end

Then /^the game is declared a draw$/ do
#@game.draw?.should be_true
expect(@game.draw?).to be true
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)
expect(@game).to receive(:get_player_move).twice.and_return(@taken_spot, arg1)
#@game.player_move.should eq arg1.to_sym
expect(@game.player_move).to eq arg1.to_sym
end
122 changes: 122 additions & 0 deletions final/features/step_definitions/tic_tac_toe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#UW Ruby class Fall 2014 joseph Simpson
class TicTacToe
PLAYERS = [:player, :computer]
SYMBOLS = [:X, :O]
attr_accessor :player, :board

def initialize(initial_player = nil, initial_symbol=nil)
@current_player = initial_player || PLAYERS.sample
@player_symbol = initial_symbol || SYMBOLS.sample

@board = {
:A1 => '', :A2 => '', :A3 => '',
:B1 => '', :B2 => '', :B3 => '',
:C1 => '', :C2 => '', :C3 => ''
}
end

def welcome_player
"Welcome #{@player}"
end

def current_player
{:player => @player, :computer => 'Computer' } [@current_player]
end

def player_symbol
@player_symbol
end
3
def computer_symbol
if current_player == 'Computer'
computer_symbol = {:X => :X, :O => :O}[@player_symbol]
else
computer_symbol = {:X => :O, :O => :X}[@player_symbol]
end
end

def indicate_player_turn
puts "#{current_player}'s Move:"
end

def open_spots
@empty_spots = []
@board.each { |index, vaue| @empty_spots << index if @board[index].empty? }
@empty_spots
end

def computer_move
move_spot = open_spots.sample
@board[move_spot] = { :X => 'X', :O => 'O' }[computer_symbol]
@current_player = :player
move_spot
end

def current_state
state = "#{@board[:A1]} | #{@board[:A2]} | #{@board[:A3]} \n \
#{@board[:B1]} | #{@board[:B2]} | #{@board[:B3]} \n \
#{@board[:C1]} | #{@board[:C2]} | #{@board[:C3]} \n "
end

def get_player_move
gets.chomp
end

def player_move
guard_num = 0
player_spot = get_player_move.to_sym
until open_spots.include?(player_spot) || guard_num > 10
guard_num = guard_num + 1
player_spot = get_player_move.to_sym
end
@board[player_spot] = player_symbol
@current_player = :computer
player_spot
end

def determine_winner
@player_win = false
@computer_win = false
@draw_match = false
if score_win(player_symbol)
return @player_win = true
else if score_win(computer_symbol)
return @computer_win = true
else
return @draw_match = true
end
end

end

def score_win(symbol)
return true if
@board[:A1] == symbol && @board[:A2] == symbol && @board[:A3] == symbol || #row 1
@board[:B1] == symbol && @board[:B2] == symbol && @board[:B3] == symbol || #row 2
@board[:C1] == symbol && @board[:C2] == symbol && @board[:C3] == symbol || #row 3
@board[:A1] == symbol && @board[:B1] == symbol && @board[:C1] == symbol || #column 1
@board[:A2] == symbol && @board[:B2] == symbol && @board[:C2] == symbol || #column 2
@board[:A3] == symbol && @board[:B3] == symbol && @board[:C3] == symbol || #column 3
@board[:A2] == symbol && @board[:B2] == symbol && @board[:C2] == symbol || #diagonal 1
@board[:A3] == symbol && @board[:B3] == symbol && @board[:C3] == symbol #diagonal 2

else return false
end

def player_won?
!@player_win
end

def over?
player_won? || @computer_win || open_spots.length == 0
end

def spots_open?
!open_spots.empty?
end

def draw?
!@computer_win && !@player_win
end

end
57 changes: 57 additions & 0 deletions final/features/tic-tac-toe.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 computer's 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 computer's 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 computer's turn

Scenario: Winning the Game
Given I have a started Tic-Tac-Toe game
And I am playing X
When there are three X's 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
6 changes: 6 additions & 0 deletions hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hi
gobbly gook
hi from pry
hello
hi
last line
Loading