Skip to content

Instantly share code, notes, and snippets.

View tarynsauer's full-sized avatar

Taryn Sauer tarynsauer

  • Madison, WI
View GitHub Profile
class AIPlayer < Player
def make_move(board)
ai = AI.new(self)
cell = ai.computer_move(board, self)
add_marker(board, cell)
end
end
## Updated config.ru
require './app'
run TicTacToe
## Updated app.rb
require 'rubygems'
require 'ruby_ttt'
require 'sinatra/base'
require 'shotgun'
require './game_helpers.rb'
class TicTacToe < Sinatra::Base
## env.rb
require File.join(File.expand_path(File.dirname(__FILE__)),'../../app')
require "Capybara"
require "Capybara/cucumber"
require "rspec"
module TicTacToeCapybaraTest
Capybara.app = TicTacToe
source 'https://rubygems.org'
ruby '1.9.3'
gem "sinatra"
gem "thin"
gem 'shotgun'
gem "ruby_ttt", "~> 0.3.1"
gem "cucumber"
gem "capybara"
gem "rspec"
Feature: Board
In order to play a game
As a game player
I want to make moves on the board
Background:
Given I visit the homepage
And I select 'Human' for 'Player one'
And I select 'Human' for 'Player two'
And I press 'Start game!'
include TicTacToeCapybaraTest
Given(/^I press the (\d+)A cell button$/) do |arg1|
click_button "#{arg1}A"
end
Then(/^I should see a marker in the (\d+)A cell$/) do |arg1|
expect(page).to have_css("#board button[value=\"#{arg1}A\"]", text: (/(X|O)/))
end
require 'tictactoe_constants'
class PlayerFactory
include TictactoeConstants
attr_accessor :player_one, :player_two
def initialize(type_one, type_two)
@player_one = create_player(type_one, TictactoeConstants::MARKER_X)
@player_two = create_player(type_two, TictactoeConstants::MARKER_O)
set_opponents
end
module TictactoeConstants
MARKER_X = 'X'
MARKER_O = 'O'
COMPUTER_PLAYER = 'computer'
HUMAN_PLAYER = 'human'
AI_PLAYER = 'hard computer'
HARD_LEVEL = 'hard'
EASY_LEVEL = 'easy'
end
require 'simplecov'
SimpleCov.start
require 'sinatra'
require 'rack/test' # Require Rack Test library
require 'ruby_ttt'
require 'web_board'
require 'web_game'
require 'web_game_setup'
require './game_helpers.rb'