Permalink
Browse files

Got bundler working in app ! Tried to fix sister_piece detection - br…

…oken now/undeployable
  • Loading branch information...
Dean Radcliffe
Dean Radcliffe committed Sep 30, 2010
1 parent f5d5adf commit cde48a4e57385db5a4c48a219ef0ac1c34a9db67
Showing with 87 additions and 24 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 Gemfile
  3. +30 −0 Gemfile.lock
  4. +0 −9 app/models/board.rb
  5. +15 −0 config/boot.rb
  6. +0 −2 config/environments/development.rb
  7. +20 −0 config/preinitializer.rb
  8. +5 −4 lib/console_helper.rb
  9. +9 −9 lib/notation.rb
View
@@ -14,3 +14,4 @@ doc/plugins/*
*database.yml*
/tmp/spec_server.pid
db/*.sqlite3
+.bundle/*
View
@@ -0,0 +1,7 @@
+source :gemcutter
+
+gem "rails", '2.3.5'
+gem "sqlite3-ruby", :require => "sqlite3"
+
+group :development do
+end
View
@@ -0,0 +1,30 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ actionmailer (2.3.5)
+ actionpack (= 2.3.5)
+ actionpack (2.3.5)
+ activesupport (= 2.3.5)
+ rack (~> 1.0.0)
+ activerecord (2.3.5)
+ activesupport (= 2.3.5)
+ activeresource (2.3.5)
+ activesupport (= 2.3.5)
+ activesupport (2.3.5)
+ rack (1.0.1)
+ rails (2.3.5)
+ actionmailer (= 2.3.5)
+ actionpack (= 2.3.5)
+ activerecord (= 2.3.5)
+ activeresource (= 2.3.5)
+ activesupport (= 2.3.5)
+ rake (>= 0.8.3)
+ rake (0.8.7)
+ sqlite3-ruby (1.3.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rails (= 2.3.5)
+ sqlite3-ruby
View
@@ -95,15 +95,6 @@ def consider_move(m, &block)
return considered unless block_given?
yield considered
end
-
- def sister_piece_of( a_piece, sitting_here )
- pos, piece = select do |pos, piece|
- piece.side == a_piece.side &&
- piece.function == a_piece.function &&
- pos != sitting_here
- end
- piece
- end
def in_check?( side )
king_pos, king = detect do |pos, piece|
View
@@ -104,5 +104,20 @@ def read_environment_rb
end
end
+# Bundler fun
+class Rails::Boot
+ def run
+ load_initializer
+
+ Rails::Initializer.class_eval do
+ def load_gems
+ @bundler_loaded ||= Bundler.require :default, Rails.env
+ end
+ end
+
+ Rails::Initializer.run(:set_load_path)
+ end
+end
+
# All that for this:
Rails.boot!
@@ -18,6 +18,4 @@
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :sendmail
-config.gem 'rails-footnotes'
-
ENV["MAGELLAN_ON"]="1"
View
@@ -0,0 +1,20 @@
+begin
+ require "rubygems"
+ require "bundler"
+rescue LoadError
+ raise "Could not load the bundler gem. Install it with `gem install bundler`."
+end
+
+if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
+ raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
+ "Run `gem install bundler` to upgrade."
+end
+
+begin
+ # Set up load paths for all bundled gems
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
+ Bundler.setup
+rescue Bundler::GemNotFound
+ raise RuntimeError, "Bundler couldn't find some gems." +
+ "Did you run `bundle install`?"
+end
View
@@ -3,16 +3,17 @@
# move :a2, :a4
class Object
def match; @match; end
- def match= *args; @match = Match.find(*args); end
+ def match= *args; @match = args.first.kind_of?(Match) ? args.first : Match.find(*args); end
# helper methods
def move *args
if args.length == 1
- match.moves << Move.new(:notation => args.shift.to_s)
+ match.moves << m=Move.new(:notation => args.shift.to_s)
else
- match.moves << Move.new(:from_coord => args.shift.to_s, :to_coord => args.shift.to_s)
+ match.moves << m=Move.new(:from_coord => args.shift.to_s, :to_coord => args.shift.to_s)
end
- match.board
+ return match.board if m.id
+ return m.errors.full_messages
end
def chat msg
View
@@ -48,16 +48,16 @@ def notate
mynotation = @piece_moving.abbrev.upcase.sub('P', from_coord_sym.file)
# disambiguate which piece moved if a 'sister_piece' could have moved there as well
- if( @piece_moving.function==:rook) || (@piece_moving.function==:knight)
-
- # look for a piece of the same type which also could have moved
- sister_piece_pos, sister_piece = @board.consider_move(self) do |b|
- b.sister_piece_of(@piece_moving, from_coord)
- end
+ sister_pieces = @board.values.select do |piece|
+ # [:rook, :knight, :queen].include?(piece.type) &&
+ (piece_position = @board.index(piece)) != from_coord_sym &&
+ piece.function == @piece_moving.function &&
+ piece.side == @piece_moving.side &&
+ piece.allowed_moves(@board).include?( to_coord_sym)
+ end
- if( sister_piece != nil && sister_piece.allowed_moves(@board).include?(to_coord_sym) )
- mynotation += ( from_coord_sym.file != sister_piece_pos.file) ? from_coord_sym.file : from_coord_sym.rank.to_s
- end
+ if ! sister_pieces.empty? && (other_guy_pos = @board.index(sister_pieces.first))
+ mynotation += ( from_coord_sym.file != other_guy_pos.file) ? from_coord_sym.file : from_coord_sym.rank.to_s
end
if @piece_moved_upon && (@piece_moving.side != @piece_moved_upon.side) || captured_piece_coord

0 comments on commit cde48a4

Please sign in to comment.