repo
string
commit
string
message
string
diff
string
vishwam/apod.gadget
d43651d20f3455f2c12414d090b74d7a381c0196
Version 1 of the gadget, created on 20100827.
diff --git a/Gadget.xml b/Gadget.xml new file mode 100755 index 0000000..69de7c2 --- /dev/null +++ b/Gadget.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8" ?> +<gadget> + <name>APoD</name> + <version>1.0.0.0</version> + <description>Astronomy Picture of the Day</description> + <author name="Vishwam Subramanyam"> + <info url="http://v.4261.in/projects/APoD_Gadget" /> + </author> + <hosts> + <host name="sidebar"> + <base type="HTML" apiVersion="1.0.0" src="apod.html" /> + <permissions>Full</permissions> + <platform minPlatformVersion="1.0" /> + </host> + </hosts> +</gadget> \ No newline at end of file diff --git a/apod.html b/apod.html new file mode 100755 index 0000000..2f1b50a Binary files /dev/null and b/apod.html differ diff --git a/css/apod.css b/css/apod.css new file mode 100755 index 0000000..b0f8ebf Binary files /dev/null and b/css/apod.css differ diff --git a/css/flyout.css b/css/flyout.css new file mode 100755 index 0000000..c3a490d Binary files /dev/null and b/css/flyout.css differ diff --git a/flyout.html b/flyout.html new file mode 100755 index 0000000..af55966 Binary files /dev/null and b/flyout.html differ diff --git a/images/background_frame.png b/images/background_frame.png new file mode 100755 index 0000000..d38f766 Binary files /dev/null and b/images/background_frame.png differ diff --git a/images/background_frame2.png b/images/background_frame2.png new file mode 100755 index 0000000..96a8b47 Binary files /dev/null and b/images/background_frame2.png differ diff --git a/images/default.jpg b/images/default.jpg new file mode 100755 index 0000000..a3080ba Binary files /dev/null and b/images/default.jpg differ diff --git a/images/flyout_background.png b/images/flyout_background.png new file mode 100755 index 0000000..c0a061e Binary files /dev/null and b/images/flyout_background.png differ diff --git a/js/apod.js b/js/apod.js new file mode 100755 index 0000000..f4965cd Binary files /dev/null and b/js/apod.js differ diff --git a/js/flyout.js b/js/flyout.js new file mode 100755 index 0000000..07995c2 Binary files /dev/null and b/js/flyout.js differ
xaviershay/dominion-solitaire
afcc29001340e3b08b7f44d73e8536e87ee7d4fe
bundle update
diff --git a/Gemfile.lock b/Gemfile.lock index a4d8967..d551405 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,16 +1,19 @@ GEM remote: https://rubygems.org/ specs: - ffi (1.9.6) + ffi (1.17.0) ffi-locale (1.0.1) ffi (>= 1.0.9) ffi-ncurses (0.4.0) ffi (>= 1.0.9) ffi-locale (>= 1.0.0) PLATFORMS ruby DEPENDENCIES ffi ffi-ncurses + +BUNDLED WITH + 2.4.5
xaviershay/dominion-solitaire
df0bf38b2d3d9925334f4afe2e43eee51a7a3364
Fix throne room when you have no actions in hand
diff --git a/lib/dominion/cards/throne_room.rb b/lib/dominion/cards/throne_room.rb index 4841632..bb4013f 100644 --- a/lib/dominion/cards/throne_room.rb +++ b/lib/dominion/cards/throne_room.rb @@ -1,23 +1,22 @@ Dominion::CARDS[:throne_room] = { :type => :action, :cost => 4, :description => 'Choose an action in your hand, play it twice', :behaviour => Dominion::Input.accept_cards( :strategy => Dominion::Input::Autocomplete.cards_in_hand(lambda {|card| [*card[:type]].include?(:action) }), - :prompt => lambda {|game, inputs| "action?" % (4 - inputs.length) }, + :prompt => lambda {|game, inputs| "action?" }, :each => lambda {|game, input| card = game.player[:hand].detect {|x| x[:name] == input } if card card[:behaviour][game, card] game.wrap_behaviour do card[:behaviour][game, card] end game.move_card(card, game.player[:hand], game.player[:played]) end }, - :min => 1, :max => 1 ) } diff --git a/lib/run.rb b/lib/run.rb index 08302ee..2ddc107 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,22 +1,22 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) def log(message) @log ||= File.open('debug.log', 'a') @log.puts message @log.flush end require 'dominion/game' require 'dominion/ui/ncurses/engine' game = Dominion::Game.new if ARGV[0] board = File.open(ARGV[0]).read.lines.reject {|x| x[0] == '#'[0] }.map {|x| x.chomp.downcase.tr(' ', '_').to_sym } - board += game.default_cards + board += Dominion::Game::DEFAULT_CARDS game.load_cards(*board) else game.load_all_cards end game.engine = Dominion::UI::NCurses::Engine.new game.run diff --git a/spec/cards/throne_room_spec.rb b/spec/cards/throne_room_spec.rb index eed2c6e..d32892a 100644 --- a/spec/cards/throne_room_spec.rb +++ b/spec/cards/throne_room_spec.rb @@ -1,43 +1,38 @@ require 'spec_helper' describe_card :throne_room, :needs_cards => [:woodcutter, :moneylender] do it_should_behave_like 'an action card' describe 'when played' do it 'allows me to play an action card in my hand twice' do hand cards(:woodcutter, 1) playing_card do input 'Woodcutter' end player[:buys].should == 3 player[:gold].should == 4 hand.should have_cards([]) played.should have_cards(cards(:throne_room, 1) + cards(:woodcutter, 1)) end it 'does nothing when no action cards in hand' do playing_card - end - - it 'forces me to choose an action' do - hand cards(:woodcutter, 1) - playing_card - game.should have_prompt + game.should_not have_prompt end it 'allows me to play an action card in my hand that requires input twice' do hand cards(:moneylender, 1) + cards(:copper, 2) playing_card do input 'Moneylender' input 'y' input 'y' end trash.should have_cards(cards(:copper, 2)) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index eef57d8..c6f9582 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,174 +1,178 @@ require 'spec' require 'rr' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| case autocomplete_strategy when :cards_in_hand then to_match = game.player[:hand].uniq to_not_match = (game.board.map(&:first) - to_match).uniq when :actions_in_hand then to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } to_not_match = game.player[:hand] - to_match when :buyable_cards then cards = game.board.map(&:first) to_match = cards.select {|x| x[:cost] <= game.treasure(game.player) } to_not_match = cards - to_match end to_match.each do |card| game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] game.prompt[:autocomplete][:card_active][card].should == true end to_not_match.each do |card| game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil game.prompt[:autocomplete][:card_active][card].should == false end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end + + failure_message_for_should_not do |game| + "expected no prompt but found: '%s'" % game.prompt[:prompt] + end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) game.engine = Dominion::Engine.new end end def game @game end def card(key) subject unless @game @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt prompt[:accept][prompt[:autocomplete][:strategy][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player subject unless @game @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros config.mock_with :rr end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end def log(*args) end
xaviershay/dominion-solitaire
f1c88c2fc6f0efb42fc309b85bf527f88a122ded
Refactor to use card matchers
diff --git a/lib/dominion/card.rb b/lib/dominion/card.rb index 15f5dcf..0c21fab 100644 --- a/lib/dominion/card.rb +++ b/lib/dominion/card.rb @@ -1,31 +1,49 @@ module Dominion # Methods to deal with cards. # # Requires an accessor +cards+ in the containing class to contain an array # of all the loaded cards. module Card + def in_hand + lambda {|x| player[:hand].include?(x) } + end + + def card(key) + cards[key] || raise("No card #{key}") + end + + def card_array(key, number) + [card(key)] * number + end + end + + # Generic matchers that are mixed into the global namespace + module CardMatchers def type?(card, type) [*card[:type]].include?(type) end def by_type(type) lambda {|x| type?(x, type) } end - def in_hand - lambda {|x| player[:hand].include?(x) } - end - def match_card(*keys) + by_key *keys + end + + def by_key(*keys) lambda {|x| keys.include? x[:key] } end - def card(key) - cards[key] || raise("No card #{key}") + def by_name(name) + lambda {|x| x[:name] == name } end - def card_array(key, number) - [card(key)] * number + def costing_lte(cost) + lambda {|x| x[:cost] <= cost } end + end end + +include Dominion::CardMatchers diff --git a/lib/dominion/cards/feast.rb b/lib/dominion/cards/feast.rb index 1e19f88..b41013c 100644 --- a/lib/dominion/cards/feast.rb +++ b/lib/dominion/cards/feast.rb @@ -1,19 +1,19 @@ Dominion::CARDS[:feast] = { :type => :action, :cost => 4, :description => 'Trash this, Gain a card costing <= 5', :behaviour => Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards {|x| x[:cost] <= 5 }, + :strategy => Dominion::Input::Autocomplete.cards(&costing_lte(5)), :prompt => lambda {|game, inputs| "gain card?" }, :each => lambda {|game, input| game.gain_card(game.board, game.player, input) }, :after => lambda {|game, inputs| - card = game.player[:played].detect {|x| x[:key] == :feast } + card = game.player[:played].detect(&by_key(:feast)) game.move_card(card, game.player[:played], game.player[:trash]) }, :max => 1, :min => 1 ) } diff --git a/lib/dominion/cards/mine.rb b/lib/dominion/cards/mine.rb index 6c7a842..b233759 100644 --- a/lib/dominion/cards/mine.rb +++ b/lib/dominion/cards/mine.rb @@ -1,33 +1,34 @@ Dominion::CARDS[:mine] = { :type => :action, :cost => 4, :description => 'Trash a T, gain a T costing up to +3T more', :behaviour => lambda {|game, card| Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards {|c| [*c[:type]].include?(:treasure) }, + :strategy => Dominion::Input::Autocomplete.cards(&by_type(:treasure)), :prompt => lambda {|game, card| "trash treasure?" }, :min => 1, :max => 1, :after => lambda {|game, inputs| unless inputs.empty? - trashed_card = game.player[:hand].detect {|x| x[:name] == inputs.first } + trashed_card = game.player[:hand].detect(&by_name(inputs[0])) game.move_card(trashed_card, game.player[:hand], game.player[:trash]) Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards {|card| - card[:cost] <= trashed_card[:cost] + 3 && [*card[:type]].include?(:treasure) }, + :strategy => Dominion::Input::Autocomplete.cards(&( + by_type(:treasure) & costing_lte(trashed_card[:cost] + 3) + )), :prompt => lambda {|game, card| "gain treasure <= #{trashed_card[:cost] + 3}T?" }, :min => 1, :max => 1, :each => lambda {|game, input| if card = game.gain_card(game.board, game.player, input) game.move_card(card, game.player[:discard], game.player[:hand]) end } )[game, card] end } )[game, card] } } diff --git a/lib/dominion/cards/remodel.rb b/lib/dominion/cards/remodel.rb index 57091c4..b606bda 100644 --- a/lib/dominion/cards/remodel.rb +++ b/lib/dominion/cards/remodel.rb @@ -1,30 +1,29 @@ Dominion::CARDS[:remodel] = { :type => :action, :cost => 4, :description => 'Trash a card, gain a card cost up to +2T more', :behaviour => lambda {|game, card| Dominion::Input.accept_cards( :strategy => Dominion::Input::Autocomplete.cards_in_hand, :prompt => lambda {|game, card| "trash card?" }, :min => 1, :max => 1, :after => lambda {|game, inputs| unless inputs.empty? - trashed_card = game.player[:hand].detect {|x| x[:name] == inputs.first } + trashed_card = game.player[:hand].detect(&by_name(inputs[0])) game.move_card(trashed_card, game.player[:hand], game.player[:trash]) Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards {|card| - card[:cost] <= trashed_card[:cost] + 2 }, + :strategy => Dominion::Input::Autocomplete.cards(&costing_lte(trashed_card[:cost] + 2)), :prompt => lambda {|game, card| "gain card <= #{trashed_card[:cost] + 2}T?" }, :min => 1, :max => 1, :each => lambda {|game, input| game.gain_card(game.board, game.player, input) } )[game, card] end } )[game, card] } } diff --git a/lib/dominion/cards/workshop.rb b/lib/dominion/cards/workshop.rb index b907479..a7e1d73 100644 --- a/lib/dominion/cards/workshop.rb +++ b/lib/dominion/cards/workshop.rb @@ -1,14 +1,14 @@ Dominion::CARDS[:workshop] = { :type => :action, :cost => 3, :description => 'Gain a card costing <= 4', :behaviour => Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards {|x| x[:cost] <= 4}, + :strategy => Dominion::Input::Autocomplete.cards(&costing_lte(4)), :prompt => lambda {|game, inputs| "gain card?" }, :each => lambda {|game, input| game.gain_card(game.board, game.player, input) }, :max => 1, :min => 1 ) }
xaviershay/dominion-solitaire
9fa8e145770e41d12b6295cf4a89b6030533c68f
Refactoring autocomplete
diff --git a/README b/README index 304bdd9..382b6d3 100644 --- a/README +++ b/README @@ -1,14 +1,29 @@ = Dominion Solitaire An ncurses Dominion implementation with a focus on lightning quick goldfishing. You play cards by typing their name with smart autocomplete. Only the base set is implemented currently. There's still a few rough edges (don't press the arrow keys, don't buy all of a card) == Running -I haven't totally automated some ncurses stuff yet - you may need the following env settings to get things working +I haven't totally automated some ncurses stuff yet - you may need the following env settings to get things working: ls /usr/lib/ | grep libncurses # Find your libncurses .dylib export RUBY_FFI_NCURSES_LIB=libncurses # Tell ffi-ncurses to use the right one rake run + +== The Code + +The code is stylistically a bit different from typical ruby code. It is mostly done in a very functional style, so there are a lot of lambdas. The core game logic is in +dominion/game.rb+, and that is a good place to start reading. All UI is abstracted out into +dominion/ui/ncurses/engine.rb+, allowing for a headless mode for testing, and other pluggable UIs in the future. Each card is implemented in its own file in +dominion/cards+, and they are all well specced. (In contrast, the specs for the game logic and ui were retrofitted later and are not as thorough.) + +== Extras + +To play a specific board, create a text file with one card name per line: + + Chapel + Smithy + +Then launch the code as such: + + ruby lib/run.rb chapel_smithy_board.txt diff --git a/lib/core_ext/proc.rb b/lib/core_ext/proc.rb new file mode 100644 index 0000000..4c23aa4 --- /dev/null +++ b/lib/core_ext/proc.rb @@ -0,0 +1,5 @@ +class Proc + def &(other) + lambda {|*args| self[*args] && other[*args] } + end +end diff --git a/lib/dominion/board.rb b/lib/dominion/board.rb index a2174ac..096aaf5 100644 --- a/lib/dominion/board.rb +++ b/lib/dominion/board.rb @@ -1,33 +1,31 @@ +require 'dominion/card' + module Dominion - # Methods to populate the initial board. Requires an accessor +cards+ in + # Methods to populate the initial board. + # + # Requires an accessor +cards+ in # the containing class to contain an array of all the loaded cards module Board + include Dominion::Card + DEFAULT_CARDS = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] DEFAULT_AMOUNT = 8 AMOUNTS = { :copper => 60, :silver => 40, :gold => 30 } def board @board ||= begin (card_set & cards.keys).map {|x| card_array(x, AMOUNTS[x] || DEFAULT_AMOUNT) } end end def card_set DEFAULT_CARDS + randomize(cards.keys - DEFAULT_CARDS)[0..9] end - - def card(key) - cards[key] || raise("No card #{key}") - end - - def card_array(key, number) - [card(key)] * number - end end end diff --git a/lib/dominion/card.rb b/lib/dominion/card.rb index 686ea4a..15f5dcf 100644 --- a/lib/dominion/card.rb +++ b/lib/dominion/card.rb @@ -1,11 +1,31 @@ module Dominion + # Methods to deal with cards. + # + # Requires an accessor +cards+ in the containing class to contain an array + # of all the loaded cards. module Card def type?(card, type) [*card[:type]].include?(type) end + + def by_type(type) + lambda {|x| type?(x, type) } + end + + def in_hand + lambda {|x| player[:hand].include?(x) } + end def match_card(*keys) lambda {|x| keys.include? x[:key] } end + + def card(key) + cards[key] || raise("No card #{key}") + end + + def card_array(key, number) + [card(key)] * number + end end end diff --git a/lib/dominion/cards/feast.rb b/lib/dominion/cards/feast.rb index 497d7ad..1e19f88 100644 --- a/lib/dominion/cards/feast.rb +++ b/lib/dominion/cards/feast.rb @@ -1,19 +1,19 @@ Dominion::CARDS[:feast] = { :type => :action, :cost => 4, :description => 'Trash this, Gain a card costing <= 5', :behaviour => Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards_on_board(lambda {|x| x[:cost] <= 5}), + :strategy => Dominion::Input::Autocomplete.cards {|x| x[:cost] <= 5 }, :prompt => lambda {|game, inputs| "gain card?" }, :each => lambda {|game, input| game.gain_card(game.board, game.player, input) }, :after => lambda {|game, inputs| card = game.player[:played].detect {|x| x[:key] == :feast } game.move_card(card, game.player[:played], game.player[:trash]) }, :max => 1, :min => 1 ) } diff --git a/lib/dominion/cards/mine.rb b/lib/dominion/cards/mine.rb index 3f15253..6c7a842 100644 --- a/lib/dominion/cards/mine.rb +++ b/lib/dominion/cards/mine.rb @@ -1,32 +1,33 @@ Dominion::CARDS[:mine] = { :type => :action, :cost => 4, :description => 'Trash a T, gain a T costing up to +3T more', :behaviour => lambda {|game, card| Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards_in_hand(lambda {|c| [*c[:type]].include?(:treasure) }), + :strategy => Dominion::Input::Autocomplete.cards {|c| [*c[:type]].include?(:treasure) }, :prompt => lambda {|game, card| "trash treasure?" }, :min => 1, :max => 1, :after => lambda {|game, inputs| unless inputs.empty? trashed_card = game.player[:hand].detect {|x| x[:name] == inputs.first } game.move_card(trashed_card, game.player[:hand], game.player[:trash]) Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards_on_board(lambda {|card| card[:cost] <= trashed_card[:cost] + 3 && [*card[:type]].include?(:treasure) }), + :strategy => Dominion::Input::Autocomplete.cards {|card| + card[:cost] <= trashed_card[:cost] + 3 && [*card[:type]].include?(:treasure) }, :prompt => lambda {|game, card| "gain treasure <= #{trashed_card[:cost] + 3}T?" }, :min => 1, :max => 1, :each => lambda {|game, input| if card = game.gain_card(game.board, game.player, input) game.move_card(card, game.player[:discard], game.player[:hand]) end } )[game, card] end } )[game, card] } } diff --git a/lib/dominion/cards/remodel.rb b/lib/dominion/cards/remodel.rb index 43e6857..57091c4 100644 --- a/lib/dominion/cards/remodel.rb +++ b/lib/dominion/cards/remodel.rb @@ -1,29 +1,30 @@ Dominion::CARDS[:remodel] = { :type => :action, :cost => 4, :description => 'Trash a card, gain a card cost up to +2T more', :behaviour => lambda {|game, card| Dominion::Input.accept_cards( :strategy => Dominion::Input::Autocomplete.cards_in_hand, :prompt => lambda {|game, card| "trash card?" }, :min => 1, :max => 1, :after => lambda {|game, inputs| unless inputs.empty? trashed_card = game.player[:hand].detect {|x| x[:name] == inputs.first } game.move_card(trashed_card, game.player[:hand], game.player[:trash]) Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards_on_board(lambda {|card| card[:cost] <= trashed_card[:cost] + 2 }), + :strategy => Dominion::Input::Autocomplete.cards {|card| + card[:cost] <= trashed_card[:cost] + 2 }, :prompt => lambda {|game, card| "gain card <= #{trashed_card[:cost] + 2}T?" }, :min => 1, :max => 1, :each => lambda {|game, input| game.gain_card(game.board, game.player, input) } )[game, card] end } )[game, card] } } diff --git a/lib/dominion/cards/workshop.rb b/lib/dominion/cards/workshop.rb index 9672c11..b907479 100644 --- a/lib/dominion/cards/workshop.rb +++ b/lib/dominion/cards/workshop.rb @@ -1,14 +1,14 @@ Dominion::CARDS[:workshop] = { :type => :action, :cost => 3, :description => 'Gain a card costing <= 4', :behaviour => Dominion::Input.accept_cards( - :strategy => Dominion::Input::Autocomplete.cards_on_board(lambda {|x| x[:cost] <= 4}), + :strategy => Dominion::Input::Autocomplete.cards {|x| x[:cost] <= 4}, :prompt => lambda {|game, inputs| "gain card?" }, :each => lambda {|game, input| game.gain_card(game.board, game.player, input) }, :max => 1, :min => 1 ) } diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index f67b855..d6903b7 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,149 +1,149 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' require 'dominion/card' require 'dominion/autoplay' +require 'core_ext/proc' module Dominion # The main game logic. See #run. class Game + include Dominion::Card include Dominion::Util include Dominion::Player include Dominion::Board - include Dominion::Card include Dominion::Autoplay attr_accessor :engine, :cards, :turn, :prompt def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end def step skip = false + if self.prompt.nil? - if player[:actions] > 0 && player[:hand].detect {|x| type?(x, :action) } + if player[:actions] > 0 && player[:hand].detect(&by_type(:action)) return if autoplay! self.prompt = { :prompt => "action (#{player[:actions]} left)?", - :autocomplete => Input::Autocomplete.cards {|card| - type?(card, :action) && player[:hand].include?(card) - }[self], + :autocomplete => Input::Autocomplete.cards(&(by_type(:action) & in_hand))[self], :color => :green_back, :accept => accept( :accept => lambda {|input| play_card(player, input) }, :decline => lambda {|input| player[:actions] = 0 } ) } elsif player[:buys] > 0 self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, :accept => accept( :accept => lambda {|input| buy_card(board, player, input) }, :decline => lambda {|input| player[:buys] = 0 } ) } else cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end # The main game loop. Will not return, use CTRL+C to exit. def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def treasure(player) player[:gold] + player[:hand].select {|x| type?(x, :treasure) }.map {|x| x[:gold] }.inject(0) {|a, b| a + b } end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end def self.instance @instance ||= new end private def accept(config) lambda {|input| self.prompt = nil if input config[:accept][input] else config[:decline][input] end } end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end end CARDS = {} end diff --git a/lib/dominion/input.rb b/lib/dominion/input.rb index 990f760..d5ef7c8 100644 --- a/lib/dominion/input.rb +++ b/lib/dominion/input.rb @@ -1,91 +1,86 @@ module Dominion class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.prompt = { :prompt => opts[:prompt][game, inputs], :autocomplete => opts[:strategy][game], :accept => lambda {|input| if input inputs << input existing = game.prompt game.prompt = nil opts[:each].call(game, input) if opts[:each] unless game.prompt || (opts[:max] && inputs.length >= opts[:max]) game.prompt = existing game.prompt[:prompt] = opts[:prompt].call(game, inputs) end else if !opts[:min] || inputs.length >= opts[:min] game.prompt = nil end end if opts[:after] && game.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete - def self.cards(&match_func) - lambda {|game| { - :card_active => lambda {|card| - match_func.call(card) - }, - :strategy => lambda {|input| - suggest = input.length == 0 ? nil : game.board.map(&:first).detect {|x| - match_func.call(x) && x[:name] =~ /^#{input}/i - } + def self.name_starts_with(input) + lambda {|x| x[:name] =~ /^#{input}/i } + end + + def self.in_stack(stack) + lambda {|card| stack.include?(card) } + end + + def self.autocomplete(source, match_func) + { + :card_active => match_func & in_stack(source), + :strategy => lambda {|input| + suggest = input.length == 0 ? nil : source.detect(&( + match_func & name_starts_with(input) + )) suggest ? suggest[:name] : nil } - }} + } end - def self.cards_on_board(match_func = lambda {|x| true }) + def self.cards(match_func = nil, &block) + if block + raise("Can't specify block and lambda") if match_func + match_func = block + elsif match_func.nil? + match_func = lambda {|x| true } + end + lambda {|game| - { - :card_active => lambda {|card| match_func[card] }, - :strategy => lambda {|input| - suggest = input.length == 0 ? nil : game.board.detect {|x| - x[0][:name] =~ /^#{input}/i && match_func[x[0]] - } - suggest ? suggest[0][:name] : nil - } - } + autocomplete(game.board.map(&:first), match_func) } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| - { - :card_active => lambda {|card| match_func[card] }, - :strategy => lambda {|input| - suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| - x[:name] =~ /^#{input}/i && match_func[x] - } - suggest ? suggest[:name] : nil - } - } + autocomplete(game.player[:hand], match_func) } end def self.boolean - lambda {|game| - { + lambda {|game| { :card_active => lambda {|card| false }, :strategy => lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } - } - } + }} end end end end diff --git a/lib/dominion/player.rb b/lib/dominion/player.rb index dc55cb1..288c5ad 100644 --- a/lib/dominion/player.rb +++ b/lib/dominion/player.rb @@ -1,144 +1,150 @@ +require 'dominion/card' + module Dominion + # Methods for moving cards around the different areas module Player + include Dominion::Card + def player=(value) @player = value end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :trashed => [], - :deck => randomize( - [cards[:estate]] * 3 + - [cards[:copper]] * 7 - ).compact + :deck => randomize(default_deck).compact } end + def default_deck + card_array(:estate, 3) + card_array(:copper, 7) + end + def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] # Following three are for logging only player[:discarded] = [] player[:trashed] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ce397b3..eef57d8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,197 +1,174 @@ require 'spec' require 'rr' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| case autocomplete_strategy - when :cards_in_hand then - # TODO: Make this match the :actions_in_hand one - game.prompt - begin - old_player = game.player.dup - - game.player[:deck] = [game.card(:estate)] - game.player[:hand] = [game.card(:copper)] - game.prompt[:autocomplete][:strategy]['co'].should == 'Copper' - game.prompt[:autocomplete][:strategy]['es'].should == nil - game.prompt[:autocomplete][:strategy]['ce'].should == nil - ensure - game.player = old_player - end - - when :actions_in_hand then - to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } - to_not_match = game.player[:hand] - to_match - - to_match.each do |card| - game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] - game.prompt[:autocomplete][:card_active][card].should == true - end - - to_not_match.each do |card| - game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil - game.prompt[:autocomplete][:card_active][card].should == false - end - - when :buyable_cards then - cards = game.board.map(&:first) - to_match = cards.select {|x| x[:cost] <= game.treasure(game.player) } - to_not_match = cards - to_match - - to_match.each do |card| - game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] - game.prompt[:autocomplete][:card_active][card].should == true - end - - to_not_match.each do |card| - game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil - game.prompt[:autocomplete][:card_active][card].should == false - end + when :cards_in_hand then + to_match = game.player[:hand].uniq + to_not_match = (game.board.map(&:first) - to_match).uniq + when :actions_in_hand then + to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } + to_not_match = game.player[:hand] - to_match + + when :buyable_cards then + cards = game.board.map(&:first) + to_match = cards.select {|x| x[:cost] <= game.treasure(game.player) } + to_not_match = cards - to_match + end + + to_match.each do |card| + game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] + game.prompt[:autocomplete][:card_active][card].should == true + end + to_not_match.each do |card| + game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil + game.prompt[:autocomplete][:card_active][card].should == false end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) game.engine = Dominion::Engine.new end end def game @game end def card(key) subject unless @game @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt prompt[:accept][prompt[:autocomplete][:strategy][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player subject unless @game @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros config.mock_with :rr end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end def log(*args) end
xaviershay/dominion-solitaire
01f565cc5379defaf6cb328b25427f46e43e87c5
Description for Chancellor
diff --git a/lib/dominion/cards/chancellor.rb b/lib/dominion/cards/chancellor.rb index 05f139a..9eb48cf 100644 --- a/lib/dominion/cards/chancellor.rb +++ b/lib/dominion/cards/chancellor.rb @@ -1,19 +1,20 @@ Dominion::CARDS[:chancellor] = { :type => :action, :cost => 3, :gold => 2, + :description => 'Optionally discard your deck', :behaviour => lambda {|game, card| game.prompt = { :prompt => "Discard your deck (y/N)?", :autocomplete => Dominion::Input::Autocomplete.boolean[game], :accept => lambda {|input| if input == 'Y' game.player[:discard] += game.player[:deck] game.player[:deck] = [] end game.prompt = nil } } } }
xaviershay/dominion-solitaire
198da99d9bbe9eab1956232f5bb4f6952043d5db
Shuffling around NCurses stuff
diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb deleted file mode 100644 index d0a3152..0000000 --- a/lib/dominion/ui.rb +++ /dev/null @@ -1,102 +0,0 @@ -require 'ffi-ncurses' -require 'dominion/engine' -require 'dominion/ui/ncurses/window' -require 'dominion/ui/ncurses/board_window' -require 'dominion/ui/ncurses/play_area_window' -require 'dominion/ui/ncurses/input_window' - -module Dominion; module UI; end; end; -class Dominion::UI::NCurses < Dominion::Engine - include FFI::NCurses - include Colour - - attr_accessor :input_buffer - - def initialize - self.input_buffer = '' - end - - def setup - super - - initscr - start_color - noecho - - [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE].each_with_index do |color, index| - init_pair(index, color, BLACK) - init_pair(index + 8, BLACK, color) - end - end - - BACKSPACE = 127 - ENTER = 10 - - def step(game, ctx) - ch = wgetch(ctx[:input_window]) - - if game.prompt - case ch - when ENTER - autocompleted = game.prompt[:autocomplete][:strategy][input_buffer] - if !(autocompleted == nil && input_buffer.length > 0) - game.prompt[:accept][autocompleted] - end - self.input_buffer = '' - when BACKSPACE - self.input_buffer = input_buffer[0..-2] - else - if ch.chr =~ /^[a-z ]+$/i - self.input_buffer += ch.chr - end - end - end - end - - def finalize - endwin - end - - def draw(game, ctx = {}) - ctx[:windows] ||= {} - curs_set 0 - refresh - - drawn = [ - BoardWindow.new(game), - PlayAreaWindow.new(game), - InputWindow.new(game, input_buffer) - ].map do |window| - c = window.coords - board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) - - if window.border - board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) - - window.window = board - window.draw - - wattr_set board_frame, A_NORMAL, 7, nil - box(board_frame, c[2], c[3]) - wmove(board_frame, 0, 2) - waddstr(board_frame, "| #{window.title} |") - wrefresh(board_frame) - wrefresh(board) - { - :frame => board_frame, - :inner => board - } - else - window.window = board_frame - window.draw - wrefresh(board_frame) - { - :frame => nil, - :inner => board_frame - } - end - end - - {:input_window => drawn[0][:inner]} - end -end diff --git a/lib/dominion/ui/ncurses/board_window.rb b/lib/dominion/ui/ncurses/board_window.rb index cd80755..e860b4e 100644 --- a/lib/dominion/ui/ncurses/board_window.rb +++ b/lib/dominion/ui/ncurses/board_window.rb @@ -1,73 +1,72 @@ -module Dominion; module UI; end; end; -class Dominion::UI::NCurses < Dominion::Engine +module Dominion::UI::NCurses class BoardWindow < Window def initialize(*args) super end def coords [14, 80, 0, 0] end def title 'Board' end def draw type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print( :white, ' ' ) if i > 0 print( :yellow, card[:cost] ) print( :red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1] ) print( :blue, pile.size ) print( :white, " %s" % card[:name] ) end print( :white, "\n" ) body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print( :white, ' ' ) print( :yellow, card[:cost] ) print( :red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1] ) print( :blue, '%-2i' % pile.size ) if game.card_active?(card) print( :white, " %-#{max_name_length}s " % card[:name], true ) else print( :white, " %-#{max_name_length}s " % card[:name] ) end print( :cyan_back, card[:cards] || ' ' ) print( :green_back, card[:actions] || ' ' ) print( :magenta_back, card[:buys] || ' ' ) print( :yellow_back, card[:gold] || ' ' ) print( :white, " %-#{max_name_length}s\n" % card[:description] ) end end end end diff --git a/lib/dominion/ui/ncurses/engine.rb b/lib/dominion/ui/ncurses/engine.rb new file mode 100644 index 0000000..6206dad --- /dev/null +++ b/lib/dominion/ui/ncurses/engine.rb @@ -0,0 +1,111 @@ +require 'ffi-ncurses' +require 'dominion/engine' + +module Dominion + module UI + module NCurses + end + end +end + +require 'dominion/ui/ncurses/window' +require 'dominion/ui/ncurses/board_window' +require 'dominion/ui/ncurses/play_area_window' +require 'dominion/ui/ncurses/input_window' + +module Dominion::UI::NCurses + class Engine < Dominion::Engine + include FFI::NCurses + include Colour + + attr_accessor :input_buffer + + def initialize + self.input_buffer = '' + end + + def setup + super + + initscr + start_color + noecho + + [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE].each_with_index do |color, index| + init_pair(index, color, BLACK) + init_pair(index + 8, BLACK, color) + end + end + + BACKSPACE = 127 + ENTER = 10 + + def step(game, ctx) + ch = wgetch(ctx[:input_window]) + + if game.prompt + case ch + when ENTER + autocompleted = game.prompt[:autocomplete][:strategy][input_buffer] + if !(autocompleted == nil && input_buffer.length > 0) + game.prompt[:accept][autocompleted] + end + self.input_buffer = '' + when BACKSPACE + self.input_buffer = input_buffer[0..-2] + else + if ch.chr =~ /^[a-z ]+$/i + self.input_buffer += ch.chr + end + end + end + end + + def finalize + endwin + end + + def draw(game, ctx = {}) + ctx[:windows] ||= {} + curs_set 0 + refresh + + drawn = [ + BoardWindow.new(game), + PlayAreaWindow.new(game), + InputWindow.new(game, input_buffer) + ].map do |window| + c = window.coords + board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) + + if window.border + board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) + + window.window = board + window.draw + + wattr_set board_frame, A_NORMAL, 7, nil + box(board_frame, c[2], c[3]) + wmove(board_frame, 0, 2) + waddstr(board_frame, "| #{window.title} |") + wrefresh(board_frame) + wrefresh(board) + { + :frame => board_frame, + :inner => board + } + else + window.window = board_frame + window.draw + wrefresh(board_frame) + { + :frame => nil, + :inner => board_frame + } + end + end + + {:input_window => drawn[0][:inner]} + end + end +end diff --git a/lib/dominion/ui/ncurses/input_window.rb b/lib/dominion/ui/ncurses/input_window.rb index 12a2c3d..d9ae443 100644 --- a/lib/dominion/ui/ncurses/input_window.rb +++ b/lib/dominion/ui/ncurses/input_window.rb @@ -1,38 +1,37 @@ -module Dominion; module UI; end; end; -class Dominion::UI::NCurses < Dominion::Engine +module Dominion::UI::NCurses class InputWindow < Window attr_accessor :input_buffer def initialize(game, input_buffer) super(game) self.input_buffer = input_buffer end def coords [1, 80, 24, 0] end def border false end def draw if game.prompt suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s print( game.prompt[:color] || :yellow_back, "%s %s" % [ game.prompt[:prompt], input_buffer ]) fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print( :red, "%s" % fill ) end else print( :green_back, "%-80s" % " " ) end end end end diff --git a/lib/dominion/ui/ncurses/play_area_window.rb b/lib/dominion/ui/ncurses/play_area_window.rb index 9589253..e75206b 100644 --- a/lib/dominion/ui/ncurses/play_area_window.rb +++ b/lib/dominion/ui/ncurses/play_area_window.rb @@ -1,48 +1,47 @@ -module Dominion; module UI; end; end; -class Dominion::UI::NCurses < Dominion::Engine +module Dominion::UI::NCurses class PlayAreaWindow < Window def initialize(*args) super end def coords [10, 80, 14, 0] end def title "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ] end def draw print( :white, "Hand: " ) line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' print( :white, card[:name] + suffix, game.card_active?(card) ) line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print( :white, " " * (77 - line_length) ) if line_length < 76 print( :white, "\n" ) played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print( :white, played ) print( :white, " " * (77 - played.length) ) if played.length < 76 print( :white, "\n" ) unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print( :white, revealed ) print( :white, " " * (77 - revealed.length) ) end end end end diff --git a/lib/dominion/ui/ncurses/window.rb b/lib/dominion/ui/ncurses/window.rb index 9c81da5..0bcf0cf 100644 --- a/lib/dominion/ui/ncurses/window.rb +++ b/lib/dominion/ui/ncurses/window.rb @@ -1,36 +1,35 @@ -module Dominion; module UI; end; end; -class Dominion::UI::NCurses < Dominion::Engine +module Dominion::UI::NCurses class Window include FFI::NCurses attr_accessor :window, :game def initialize(game) self.game = game end def print(color, text, bold = false) color_index = colors[color] || raise("Unknown color: #{color}") wattr_set window, bold ? A_BOLD : A_NORMAL, color_index, nil waddstr(window, text.to_s) end def colors { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 } end def border true end end end diff --git a/lib/run.rb b/lib/run.rb index 266ded0..08302ee 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,22 +1,22 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) def log(message) @log ||= File.open('debug.log', 'a') @log.puts message @log.flush end require 'dominion/game' -require 'dominion/ui' +require 'dominion/ui/ncurses/engine' game = Dominion::Game.new if ARGV[0] board = File.open(ARGV[0]).read.lines.reject {|x| x[0] == '#'[0] }.map {|x| x.chomp.downcase.tr(' ', '_').to_sym } board += game.default_cards game.load_cards(*board) else game.load_all_cards end -game.engine = Dominion::UI::NCurses.new +game.engine = Dominion::UI::NCurses::Engine.new game.run diff --git a/spec/ui_spec.rb b/spec/ui_spec.rb index 4a138a1..0a81d1b 100644 --- a/spec/ui_spec.rb +++ b/spec/ui_spec.rb @@ -1,60 +1,60 @@ require 'spec_helper' -require 'dominion/ui' +require 'dominion/ui/ncurses/engine' -describe Dominion::UI::NCurses do +describe Dominion::UI::NCurses::Engine do let(:game) { Struct.new(:prompt).new({ :autocomplete => { :strategy => lambda {|input| 'abcde' } } }) } describe '#step' do it 'accepts alphabetic input' do mock_input 'a'[0] subject.step(game, {}) subject.input_buffer.should == 'a' end it 'accepts capital input' do mock_input 'A'[0] subject.step(game, {}) subject.input_buffer.should == 'A' end it 'rejects non-alphabetic input' do mock_input '1'[0] subject.step(game, {}) subject.input_buffer.should == '' end it 'accepts backspace' do subject.input_buffer = 'abc' mock_input 127 subject.step(game, {}) subject.input_buffer.should == 'ab' end it 'accepts enter and autocompletes input' do subject.input_buffer = 'abc' mock_input 10 accepted = nil game.prompt[:accept] = lambda {|input| accepted = input } subject.step(game, {}) subject.input_buffer.should == '' accepted.should == 'abcde' end def mock_input(chr) mock(subject).wgetch(nil) { chr } end end end
xaviershay/dominion-solitaire
740146b45688962ec294b079769fffed807d8b12
Refactor UI somewhat
diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 245fe1e..d0a3152 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,246 +1,102 @@ require 'ffi-ncurses' require 'dominion/engine' +require 'dominion/ui/ncurses/window' +require 'dominion/ui/ncurses/board_window' +require 'dominion/ui/ncurses/play_area_window' +require 'dominion/ui/ncurses/input_window' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses include Colour attr_accessor :input_buffer def initialize self.input_buffer = '' end def setup super initscr start_color noecho [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE].each_with_index do |color, index| init_pair(index, color, BLACK) init_pair(index + 8, BLACK, color) end end BACKSPACE = 127 ENTER = 10 def step(game, ctx) ch = wgetch(ctx[:input_window]) if game.prompt case ch when ENTER autocompleted = game.prompt[:autocomplete][:strategy][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) game.prompt[:accept][autocompleted] end self.input_buffer = '' when BACKSPACE self.input_buffer = input_buffer[0..-2] else if ch.chr =~ /^[a-z ]+$/i self.input_buffer += ch.chr end end end end def finalize endwin end - def colors - { - :white => 0, - :yellow => 3, - :blue => 4, - :red => 1, - :cyan_back => 14, - :green_back => 10, - :magenta_back => 13, - :yellow_back => 11 - } - end - - def bold_with_color(window, game, color, text) - color_index = colors[color] || raise("Unknown color: #{color}") - wattr_set window, A_BOLD, color_index, nil - - waddstr(window, text.to_s) - end - - def print_with_color(window, game, color, text) - color_index = colors[color] || raise("Unknown color: #{color}") - wattr_set window, A_NORMAL, color_index, nil - - waddstr(window, text.to_s) - end - def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh - drawn = [{ - :coords => [14, 80, 0, 0], - :title => 'Board', - :draw => lambda do |window, game| - bwc = lambda {|color, text| bold_with_color(window, game, color, text)} - pwc = lambda {|color, text| print_with_color(window, game, color, text)} - - type_char = [ - [:reaction, 'R'], - [:attack, 'X'], - [:treasure, 'T'], - [:victory, 'V'], - [:action, 'A'] - ] - - max_name_length = game.board.map {|pile| - pile[0][:name].length - }.max - - header, body = game.board.partition {|x| - [ - :copper, - :silver, - :gold, - :estate, - :duchy, - :provence, - :curse - ].include?(x.first[:key]) - } - - header.each_with_index do |pile, i| - card = pile.first - - pwc[:white, ' '] if i > 0 - pwc[:yellow, card[:cost]] - pwc[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] - pwc[:blue, pile.size] - pwc[:white, " %s" % card[:name]] - end - pwc[:white, "\n"] - body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| - card = pile.first - - pwc[:white, ' '] - pwc[:yellow, card[:cost]] - pwc[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] - pwc[:blue, '%-2i' % pile.size] - if game.card_active?(card) - bwc[:white, " %-#{max_name_length}s " % card[:name]] - else - pwc[:white, " %-#{max_name_length}s " % card[:name]] - end - - pwc[:cyan_back, card[:cards] || ' '] - pwc[:green_back, card[:actions] || ' '] - pwc[:magenta_back, card[:buys] || ' '] - pwc[:yellow_back, card[:gold] || ' '] - - pwc[:white, " %-#{max_name_length}s\n" % card[:description]] - end - end - }, { - :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ - game.turn, - game.player[:actions], - game.player[:buys], - game.treasure(game.player), - game.player[:discard].length, - game.player[:deck].length - ], - :coords => [10, 80, 14, 0], - :draw => lambda do |window, game| - bwc = lambda {|color, text| bold_with_color(window, game, color, text)} - pwc = lambda {|color, text| print_with_color(window, game, color, text)} - - pwc[:white, "Hand: "] - line_length = 6 - game.player[:hand].each_with_index do |card, index| - suffix = index == game.player[:hand].length - 1 ? '' : ', ' - if game.card_active?(card) - bwc[:white, card[:name] + suffix] - else - pwc[:white, card[:name] + suffix] - end - line_length += (card[:name] + suffix).length - end - - # TODO: print ' ' doesn't work :( - pwc[:white, " " * (77 - line_length)] if line_length < 76 - pwc[:white, "\n"] - played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") - pwc[:white, played] - pwc[:white, " " * (77 - played.length)] if played.length < 76 - pwc[:white, "\n"] - - unless game.player[:revealed].empty? - revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") - pwc[:white, revealed] - pwc[:white, " " * (77 - revealed.length)] - end - - end - }, { - :coords => [1, 80, 24, 0], - :border => false, - :draw => lambda do |window, game| - pwc = lambda {|color, text| print_with_color(window, game, color, text)} - - if game.prompt - suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s - - pwc[game.prompt[:color] || :yellow_back, "%s %s" % [ - game.prompt[:prompt], - input_buffer]] - - fill = suggest[input_buffer.length..-1] - - if fill && fill.length > 0 - pwc[:red, "%s" % fill] - end - else - pwc[:green_back, "%-80s" % " "] - end - end - }].map do |window| - window[:border] = true unless window.has_key?(:border) - - c = window[:coords] + drawn = [ + BoardWindow.new(game), + PlayAreaWindow.new(game), + InputWindow.new(game, input_buffer) + ].map do |window| + c = window.coords board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) - if window[:border] + if window.border board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) - window[:draw][board, game] + window.window = board + window.draw wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) - waddstr(board_frame, "| #{window[:title]} |") + waddstr(board_frame, "| #{window.title} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else - window[:draw][board_frame, game] + window.window = board_frame + window.draw wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end end diff --git a/lib/dominion/ui/ncurses/board_window.rb b/lib/dominion/ui/ncurses/board_window.rb new file mode 100644 index 0000000..cd80755 --- /dev/null +++ b/lib/dominion/ui/ncurses/board_window.rb @@ -0,0 +1,73 @@ +module Dominion; module UI; end; end; +class Dominion::UI::NCurses < Dominion::Engine + class BoardWindow < Window + def initialize(*args) + super + end + + def coords + [14, 80, 0, 0] + end + + def title + 'Board' + end + + def draw + type_char = [ + [:reaction, 'R'], + [:attack, 'X'], + [:treasure, 'T'], + [:victory, 'V'], + [:action, 'A'] + ] + + max_name_length = game.board.map {|pile| + pile[0][:name].length + }.max + + header, body = game.board.partition {|x| + [ + :copper, + :silver, + :gold, + :estate, + :duchy, + :provence, + :curse + ].include?(x.first[:key]) + } + + header.each_with_index do |pile, i| + card = pile.first + + print( :white, ' ' ) if i > 0 + print( :yellow, card[:cost] ) + print( :red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1] ) + print( :blue, pile.size ) + print( :white, " %s" % card[:name] ) + end + print( :white, "\n" ) + body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| + card = pile.first + + print( :white, ' ' ) + print( :yellow, card[:cost] ) + print( :red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1] ) + print( :blue, '%-2i' % pile.size ) + if game.card_active?(card) + print( :white, " %-#{max_name_length}s " % card[:name], true ) + else + print( :white, " %-#{max_name_length}s " % card[:name] ) + end + + print( :cyan_back, card[:cards] || ' ' ) + print( :green_back, card[:actions] || ' ' ) + print( :magenta_back, card[:buys] || ' ' ) + print( :yellow_back, card[:gold] || ' ' ) + + print( :white, " %-#{max_name_length}s\n" % card[:description] ) + end + end + end +end diff --git a/lib/dominion/ui/ncurses/input_window.rb b/lib/dominion/ui/ncurses/input_window.rb new file mode 100644 index 0000000..12a2c3d --- /dev/null +++ b/lib/dominion/ui/ncurses/input_window.rb @@ -0,0 +1,38 @@ +module Dominion; module UI; end; end; +class Dominion::UI::NCurses < Dominion::Engine + class InputWindow < Window + attr_accessor :input_buffer + + def initialize(game, input_buffer) + super(game) + self.input_buffer = input_buffer + end + + def coords + [1, 80, 24, 0] + end + + def border + false + end + + def draw + if game.prompt + suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s + + print( game.prompt[:color] || :yellow_back, "%s %s" % [ + game.prompt[:prompt], + input_buffer + ]) + + fill = suggest[input_buffer.length..-1] + + if fill && fill.length > 0 + print( :red, "%s" % fill ) + end + else + print( :green_back, "%-80s" % " " ) + end + end + end +end diff --git a/lib/dominion/ui/ncurses/play_area_window.rb b/lib/dominion/ui/ncurses/play_area_window.rb new file mode 100644 index 0000000..9589253 --- /dev/null +++ b/lib/dominion/ui/ncurses/play_area_window.rb @@ -0,0 +1,48 @@ +module Dominion; module UI; end; end; +class Dominion::UI::NCurses < Dominion::Engine + class PlayAreaWindow < Window + def initialize(*args) + super + end + + def coords + [10, 80, 14, 0] + end + + def title + "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ + game.turn, + game.player[:actions], + game.player[:buys], + game.treasure(game.player), + game.player[:discard].length, + game.player[:deck].length + ] + end + + def draw + print( :white, "Hand: " ) + line_length = 6 + game.player[:hand].each_with_index do |card, index| + suffix = index == game.player[:hand].length - 1 ? '' : ', ' + print( :white, card[:name] + suffix, game.card_active?(card) ) + line_length += (card[:name] + suffix).length + end + + # TODO: print ' ' doesn't work :( + print( :white, " " * (77 - line_length) ) if line_length < 76 + print( :white, "\n" ) + + played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") + print( :white, played ) + print( :white, " " * (77 - played.length) ) if played.length < 76 + print( :white, "\n" ) + + unless game.player[:revealed].empty? + revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") + print( :white, revealed ) + print( :white, " " * (77 - revealed.length) ) + end + end + end +end diff --git a/lib/dominion/ui/ncurses/window.rb b/lib/dominion/ui/ncurses/window.rb new file mode 100644 index 0000000..9c81da5 --- /dev/null +++ b/lib/dominion/ui/ncurses/window.rb @@ -0,0 +1,36 @@ +module Dominion; module UI; end; end; +class Dominion::UI::NCurses < Dominion::Engine + class Window + include FFI::NCurses + + attr_accessor :window, :game + + def initialize(game) + self.game = game + end + + def print(color, text, bold = false) + color_index = colors[color] || raise("Unknown color: #{color}") + wattr_set window, bold ? A_BOLD : A_NORMAL, color_index, nil + + waddstr(window, text.to_s) + end + + def colors + { + :white => 0, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + } + end + + def border + true + end + end +end
xaviershay/dominion-solitaire
2e959131f5203c8dc7ca6bdb89f0a11b105474eb
Start DRYing ncurses ui
diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 8be8c33..245fe1e 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,291 +1,246 @@ require 'ffi-ncurses' require 'dominion/engine' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses include Colour attr_accessor :input_buffer def initialize self.input_buffer = '' end def setup super initscr start_color noecho [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE].each_with_index do |color, index| init_pair(index, color, BLACK) init_pair(index + 8, BLACK, color) end end BACKSPACE = 127 ENTER = 10 def step(game, ctx) ch = wgetch(ctx[:input_window]) if game.prompt case ch when ENTER autocompleted = game.prompt[:autocomplete][:strategy][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) game.prompt[:accept][autocompleted] end self.input_buffer = '' when BACKSPACE self.input_buffer = input_buffer[0..-2] else if ch.chr =~ /^[a-z ]+$/i self.input_buffer += ch.chr end end end end def finalize endwin end + def colors + { + :white => 0, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + } + end + + def bold_with_color(window, game, color, text) + color_index = colors[color] || raise("Unknown color: #{color}") + wattr_set window, A_BOLD, color_index, nil + + waddstr(window, text.to_s) + end + + def print_with_color(window, game, color, text) + color_index = colors[color] || raise("Unknown color: #{color}") + wattr_set window, A_NORMAL, color_index, nil + + waddstr(window, text.to_s) + end + def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| - bold_with_color = lambda do |color, text| - color_index = { - :white => 0, - :yellow => 3, - :blue => 4, - :red => 1, - :cyan_back => 14, - :green_back => 10, - :magenta_back => 13, - :yellow_back => 11 - }[color] || raise("Unknown color: #{color}") - wattr_set window, A_BOLD, color_index, nil - - waddstr(window, text.to_s) - end - print_with_color = lambda do |color, text| - color_index = { - :white => 0, - :yellow => 3, - :blue => 4, - :red => 1, - :cyan_back => 14, - :green_back => 10, - :magenta_back => 13, - :yellow_back => 11 - }[color] || raise("Unknown color: #{color}") - wattr_set window, A_NORMAL, color_index, nil - - waddstr(window, text.to_s) - end + bwc = lambda {|color, text| bold_with_color(window, game, color, text)} + pwc = lambda {|color, text| print_with_color(window, game, color, text)} type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first - print_with_color[:white, ' '] if i > 0 - print_with_color[:yellow, card[:cost]] - print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] - print_with_color[:blue, pile.size] - print_with_color[:white, " %s" % card[:name]] + pwc[:white, ' '] if i > 0 + pwc[:yellow, card[:cost]] + pwc[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] + pwc[:blue, pile.size] + pwc[:white, " %s" % card[:name]] end -print_with_color[:white, "\n"] + pwc[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first - print_with_color[:white, ' '] - print_with_color[:yellow, card[:cost]] - print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] - print_with_color[:blue, '%-2i' % pile.size] + pwc[:white, ' '] + pwc[:yellow, card[:cost]] + pwc[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] + pwc[:blue, '%-2i' % pile.size] if game.card_active?(card) - bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] + bwc[:white, " %-#{max_name_length}s " % card[:name]] else - print_with_color[:white, " %-#{max_name_length}s " % card[:name]] + pwc[:white, " %-#{max_name_length}s " % card[:name]] end - print_with_color[:cyan_back, card[:cards] || ' '] - print_with_color[:green_back, card[:actions] || ' '] - print_with_color[:magenta_back, card[:buys] || ' '] - print_with_color[:yellow_back, card[:gold] || ' '] + pwc[:cyan_back, card[:cards] || ' '] + pwc[:green_back, card[:actions] || ' '] + pwc[:magenta_back, card[:buys] || ' '] + pwc[:yellow_back, card[:gold] || ' '] - print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] + pwc[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| - bold_with_color = lambda do |color, text| - color_index = { - :white => 0, - :yellow => 3, - :blue => 4, - :red => 1, - :cyan_back => 14, - :green_back => 10, - :magenta_back => 13, - :yellow_back => 11 - }[color] || raise("Unknown color: #{color}") - wattr_set window, A_BOLD, color_index, nil - - waddstr(window, text.to_s) - end - print_with_color = lambda do |color, text| - color_index = { - :white => 0, - :yellow => 3, - :blue => 4, - :red => 1, - :cyan_back => 14, - :green_back => 10, - :magenta_back => 13, - :yellow_back => 11 - }[color] || raise("Unknown color: #{color}") - wattr_set window, A_NORMAL, color_index, nil - - waddstr(window, text.to_s) - end + bwc = lambda {|color, text| bold_with_color(window, game, color, text)} + pwc = lambda {|color, text| print_with_color(window, game, color, text)} - print_with_color[:white, "Hand: "] + pwc[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if game.card_active?(card) - bold_with_color[:white, card[:name] + suffix] + bwc[:white, card[:name] + suffix] else - print_with_color[:white, card[:name] + suffix] + pwc[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( - print_with_color[:white, " " * (77 - line_length)] if line_length < 76 - print_with_color[:white, "\n"] + pwc[:white, " " * (77 - line_length)] if line_length < 76 + pwc[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") - print_with_color[:white, played] - print_with_color[:white, " " * (77 - played.length)] if played.length < 76 - print_with_color[:white, "\n"] + pwc[:white, played] + pwc[:white, " " * (77 - played.length)] if played.length < 76 + pwc[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") - print_with_color[:white, revealed] - print_with_color[:white, " " * (77 - revealed.length)] + pwc[:white, revealed] + pwc[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| - print_with_color = lambda do |color, text| - color_index = { - :white => 7, - :yellow => 3, - :blue => 4, - :red => 1, - :cyan_back => 14, - :green_back => 10, - :magenta_back => 13, - :yellow_back => 11 - }[color] || raise("Unknown color: #{color}") - wattr_set window, A_NORMAL, color_index, nil - - waddstr(window, text.to_s) - end + pwc = lambda {|color, text| print_with_color(window, game, color, text)} if game.prompt - #print_with_color[:yellow_back, "%-80s" % ""] - suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s - print_with_color[game.prompt[:color] || :yellow_back, "%s %s" % [ + pwc[game.prompt[:color] || :yellow_back, "%s %s" % [ game.prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 - print_with_color[:red, "%s" % fill] + pwc[:red, "%s" % fill] end else - print_with_color[:green_back, "%-80s" % " "] + pwc[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end end
xaviershay/dominion-solitaire
97ca44c78c4b404a3346d25a1a4e41e0e1fc6805
UI#step spec
diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index e106cbc..8be8c33 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,298 +1,291 @@ require 'ffi-ncurses' require 'dominion/engine' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses + include Colour attr_accessor :input_buffer + def initialize + self.input_buffer = '' + end + def setup super - self.input_buffer = '' - initscr start_color noecho - # set up colour pairs - # Background Foreground - init_pair(0, Colour::BLACK, Colour::BLACK) - init_pair(1, Colour::RED, Colour::BLACK) - init_pair(2, Colour::GREEN, Colour::BLACK) - init_pair(3, Colour::YELLOW, Colour::BLACK) - init_pair(4, Colour::BLUE, Colour::BLACK) - init_pair(5, Colour::MAGENTA, Colour::BLACK) - init_pair(6, Colour::CYAN, Colour::BLACK) - init_pair(7, Colour::WHITE, Colour::BLACK) - - init_pair(8, Colour::BLACK, Colour::BLACK) - init_pair(9, Colour::BLACK, Colour::RED) - init_pair(10, Colour::BLACK, Colour::GREEN) - init_pair(11, Colour::BLACK, Colour::YELLOW) - init_pair(12, Colour::BLACK, Colour::BLUE) - init_pair(13, Colour::BLACK, Colour::MAGENTA) - init_pair(14, Colour::BLACK, Colour::CYAN) - init_pair(15, Colour::BLACK, Colour::WHITE) + [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE].each_with_index do |color, index| + init_pair(index, color, BLACK) + init_pair(index + 8, BLACK, color) + end end + BACKSPACE = 127 + ENTER = 10 + def step(game, ctx) ch = wgetch(ctx[:input_window]) if game.prompt case ch - when 10 + when ENTER autocompleted = game.prompt[:autocomplete][:strategy][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) game.prompt[:accept][autocompleted] end self.input_buffer = '' - when 127 + when BACKSPACE self.input_buffer = input_buffer[0..-2] else - self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i + if ch.chr =~ /^[a-z ]+$/i + self.input_buffer += ch.chr + end end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if game.card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if game.card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if game.prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s print_with_color[game.prompt[:color] || :yellow_back, "%s %s" % [ game.prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 264aa25..ce397b3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,195 +1,197 @@ require 'spec' +require 'rr' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| case autocomplete_strategy when :cards_in_hand then # TODO: Make this match the :actions_in_hand one game.prompt begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] game.prompt[:autocomplete][:strategy]['co'].should == 'Copper' game.prompt[:autocomplete][:strategy]['es'].should == nil game.prompt[:autocomplete][:strategy]['ce'].should == nil ensure game.player = old_player end when :actions_in_hand then to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } to_not_match = game.player[:hand] - to_match to_match.each do |card| game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] game.prompt[:autocomplete][:card_active][card].should == true end to_not_match.each do |card| game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil game.prompt[:autocomplete][:card_active][card].should == false end when :buyable_cards then cards = game.board.map(&:first) to_match = cards.select {|x| x[:cost] <= game.treasure(game.player) } to_not_match = cards - to_match to_match.each do |card| game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] game.prompt[:autocomplete][:card_active][card].should == true end to_not_match.each do |card| game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil game.prompt[:autocomplete][:card_active][card].should == false end end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) game.engine = Dominion::Engine.new end end def game @game end def card(key) subject unless @game @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt prompt[:accept][prompt[:autocomplete][:strategy][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player subject unless @game @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros + config.mock_with :rr end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end def log(*args) end diff --git a/spec/ui_spec.rb b/spec/ui_spec.rb new file mode 100644 index 0000000..4a138a1 --- /dev/null +++ b/spec/ui_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper' +require 'dominion/ui' + +describe Dominion::UI::NCurses do + let(:game) { + Struct.new(:prompt).new({ + :autocomplete => { + :strategy => lambda {|input| 'abcde' } + } + }) + } + + describe '#step' do + it 'accepts alphabetic input' do + mock_input 'a'[0] + + subject.step(game, {}) + subject.input_buffer.should == 'a' + end + + it 'accepts capital input' do + mock_input 'A'[0] + + subject.step(game, {}) + subject.input_buffer.should == 'A' + end + + it 'rejects non-alphabetic input' do + mock_input '1'[0] + + subject.step(game, {}) + subject.input_buffer.should == '' + end + + it 'accepts backspace' do + subject.input_buffer = 'abc' + mock_input 127 + + subject.step(game, {}) + subject.input_buffer.should == 'ab' + end + + it 'accepts enter and autocompletes input' do + subject.input_buffer = 'abc' + mock_input 10 + + accepted = nil + game.prompt[:accept] = lambda {|input| + accepted = input + } + subject.step(game, {}) + subject.input_buffer.should == '' + accepted.should == 'abcde' + end + + def mock_input(chr) + mock(subject).wgetch(nil) { chr } + end + end +end
xaviershay/dominion-solitaire
618d9ab5437fecce08223d2af6c592275ab6f6b1
Comments
diff --git a/lib/dominion/autoplay.rb b/lib/dominion/autoplay.rb index 61747c4..c1b6e4b 100644 --- a/lib/dominion/autoplay.rb +++ b/lib/dominion/autoplay.rb @@ -1,18 +1,19 @@ module Dominion + # Rules to autoplay solitaire matches, for speedier gold fishing module Autoplay CARDS_TO_AUTOPLAY = [:village, :market, :laboratory] def autoplay! ret = false unless player[:hand].detect(&match_card(:throne_room)) while to_play = player[:hand].detect(&match_card(*CARDS_TO_AUTOPLAY)) play_card(player, to_play[:name]) ret = true end end ret end end end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 6633ef2..f67b855 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,148 +1,149 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' require 'dominion/card' require 'dominion/autoplay' module Dominion + # The main game logic. See #run. class Game include Dominion::Util include Dominion::Player include Dominion::Board include Dominion::Card include Dominion::Autoplay attr_accessor :engine, :cards, :turn, :prompt def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| type?(x, :action) } return if autoplay! self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => Input::Autocomplete.cards {|card| type?(card, :action) && player[:hand].include?(card) }[self], :color => :green_back, :accept => accept( :accept => lambda {|input| play_card(player, input) }, :decline => lambda {|input| player[:actions] = 0 } ) } - elsif player[:buys] > 0 # TODO: option to skip copper buys + elsif player[:buys] > 0 self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, :accept => accept( :accept => lambda {|input| buy_card(board, player, input) }, :decline => lambda {|input| player[:buys] = 0 } ) } else - # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end + # The main game loop. Will not return, use CTRL+C to exit. def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def treasure(player) player[:gold] + player[:hand].select {|x| type?(x, :treasure) }.map {|x| x[:gold] }.inject(0) {|a, b| a + b } end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end def self.instance @instance ||= new end private def accept(config) lambda {|input| self.prompt = nil if input config[:accept][input] else config[:decline][input] end } end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end end CARDS = {} end
xaviershay/dominion-solitaire
7ab3ff787c271c74732bc94efa0ec6b2666eebb1
Refactor autoplay
diff --git a/lib/dominion/autoplay.rb b/lib/dominion/autoplay.rb new file mode 100644 index 0000000..61747c4 --- /dev/null +++ b/lib/dominion/autoplay.rb @@ -0,0 +1,18 @@ +module Dominion + module Autoplay + CARDS_TO_AUTOPLAY = [:village, :market, :laboratory] + + def autoplay! + ret = false + + unless player[:hand].detect(&match_card(:throne_room)) + while to_play = player[:hand].detect(&match_card(*CARDS_TO_AUTOPLAY)) + play_card(player, to_play[:name]) + ret = true + end + end + + ret + end + end +end diff --git a/lib/dominion/card.rb b/lib/dominion/card.rb index 7d0e09e..686ea4a 100644 --- a/lib/dominion/card.rb +++ b/lib/dominion/card.rb @@ -1,7 +1,11 @@ module Dominion module Card def type?(card, type) [*card[:type]].include?(type) end + + def match_card(*keys) + lambda {|x| keys.include? x[:key] } + end end end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 739c44c..6633ef2 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,156 +1,148 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' require 'dominion/card' +require 'dominion/autoplay' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board include Dominion::Card + include Dominion::Autoplay attr_accessor :engine, :cards, :turn, :prompt def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| type?(x, :action) } - # --- AUTOPLAY SECTION - autoplay = [:village, :market, :laboratory] - unless player[:hand].detect {|x| x[:key] == :throne_room } - while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } - play_card(player, to_play[:name]) - skip = true - end - end - - return if skip - # --- END AUTOPLAY + return if autoplay! self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => Input::Autocomplete.cards {|card| type?(card, :action) && player[:hand].include?(card) }[self], :color => :green_back, :accept => accept( :accept => lambda {|input| play_card(player, input) }, :decline => lambda {|input| player[:actions] = 0 } ) } elsif player[:buys] > 0 # TODO: option to skip copper buys self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, :accept => accept( :accept => lambda {|input| buy_card(board, player, input) }, :decline => lambda {|input| player[:buys] = 0 } ) } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def treasure(player) player[:gold] + player[:hand].select {|x| type?(x, :treasure) }.map {|x| x[:gold] }.inject(0) {|a, b| a + b } end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end def self.instance @instance ||= new end private def accept(config) lambda {|input| self.prompt = nil if input config[:accept][input] else config[:decline][input] end } end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end end CARDS = {} end
xaviershay/dominion-solitaire
c6745d7136ad5189020a686418a5d8b65121c8fe
Spec #treasure
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index c5c63f3..739c44c 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,157 +1,156 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' require 'dominion/card' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board include Dominion::Card attr_accessor :engine, :cards, :turn, :prompt def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| type?(x, :action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => Input::Autocomplete.cards {|card| type?(card, :action) && player[:hand].include?(card) }[self], :color => :green_back, :accept => accept( :accept => lambda {|input| play_card(player, input) }, :decline => lambda {|input| player[:actions] = 0 } ) } elsif player[:buys] > 0 # TODO: option to skip copper buys self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, :accept => accept( :accept => lambda {|input| buy_card(board, player, input) }, :decline => lambda {|input| player[:buys] = 0 } ) } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def treasure(player) player[:gold] + player[:hand].select {|x| type?(x, :treasure) }.map {|x| - raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end def self.instance @instance ||= new end private def accept(config) lambda {|input| self.prompt = nil if input config[:accept][input] else config[:decline][input] end } end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end end CARDS = {} end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 8e1c3c0..e11bf53 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,89 +1,112 @@ require 'spec_helper' describe Dominion::Game do subject do game_with_cards(:estate, :copper, :smithy, :chancellor) end describe '#step' do it 'does not blow up' do subject.step end describe 'when no prompt' do describe 'when actions available' do describe 'when autoplay actions in hand' do end describe 'when actions in hand' do before do hand cards(:copper, 1) + cards(:smithy, 1) subject.step end it { should have_prompt_with_autocomplete :actions_in_hand } end end describe 'when no actions left and buys available' do before do player[:actions] = 0 subject.step end it { should have_prompt_with_autocomplete :buyable_cards } end describe 'with no actions and no buys' do before do deck cards(:estate, 5) hand cards(:copper, 1) played cards(:smithy, 1) player[:actions] = player[:buys] = 0 subject.step end it('resets buys') { player[:buys ].should == 1 } it('resets actions') { player[:actions].should == 1 } it('resets gold') { player[:gold ].should == 0 } it('increments turn') { subject.turn.should == 2 } it 'moves hand and player to discard' do discard.should have_cards cards(:copper, 1) + cards(:smithy, 1) end it 'empties played' do played.should == [] end it 'draws five new cards' do hand.should have_cards cards(:estate, 5) end end end end describe '#card_active?' do let(:check_card) { card(:copper) } describe 'when no prompt' do specify { subject.card_active?(check_card).should be_false } end describe 'when prompt with autocomplete matching the given card' do before do subject.prompt = { :autocomplete => { :card_active => lambda {|card| card == check_card } } } end specify { subject.card_active?(check_card).should be_true } end end + + describe '#treasure' do + describe 'with no hand' do + before do + player[:gold] = 1 + end + + it 'should return the players gold' do + subject.treasure(player).should == 1 + end + end + + describe 'with treasure in hand' do + before do + hand cards(:copper, 2) + player[:gold] = 1 + end + + it 'should return the sum of the players gold and all treasure in hand' do + subject.treasure(player).should == 3 + end + end + end end
xaviershay/dominion-solitaire
97829aa9a9900d722ca2abae885f3142cb1b0b0b
Shuffling things around in Game
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 5711e8e..c5c63f3 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,162 +1,157 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' require 'dominion/card' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board include Dominion::Card - attr_accessor :engine, :cards, :turn + attr_accessor :engine, :cards, :turn, :prompt def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end - # An active card is one that can be interacted with. They are generally - # highlighted in the UI. - # - # card - a hash describing a card - def card_active?(card) - self.prompt && self.prompt[:autocomplete][:card_active][card] - end - - def prompt - @prompt - end - - def prompt=(value) - @prompt = value - end - - def add_card(key, values) - key = key.to_sym - cards[key] = add_defaults_to_card(key, values) - end - - def treasure(player) - player[:gold] + player[:hand].select {|x| - type?(x, :treasure) - }.map {|x| - raise x.inspect unless x[:gold] - x[:gold] - }.inject(0) {|a, b| - a + b - } - end - def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| type?(x, :action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => Input::Autocomplete.cards {|card| type?(card, :action) && player[:hand].include?(card) }[self], :color => :green_back, :accept => accept( :accept => lambda {|input| play_card(player, input) }, :decline => lambda {|input| player[:actions] = 0 } ) } elsif player[:buys] > 0 # TODO: option to skip copper buys self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, :accept => accept( :accept => lambda {|input| buy_card(board, player, input) }, :decline => lambda {|input| player[:buys] = 0 } ) } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end - - def accept(config) - lambda {|input| - self.prompt = nil - if input - config[:accept][input] - else - config[:decline][input] - end - } - end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end - def self.instance - @instance ||= new + # An active card is one that can be interacted with. They are generally + # highlighted in the UI. + # + # card - a hash describing a card + def card_active?(card) + self.prompt && self.prompt[:autocomplete][:card_active][card] + end + + def treasure(player) + player[:gold] + player[:hand].select {|x| + type?(x, :treasure) + }.map {|x| + raise x.inspect unless x[:gold] + x[:gold] + }.inject(0) {|a, b| + a + b + } end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end + + def self.instance + @instance ||= new + end + + private + + def accept(config) + lambda {|input| + self.prompt = nil + if input + config[:accept][input] + else + config[:decline][input] + end + } + end + + def add_card(key, values) + key = key.to_sym + cards[key] = add_defaults_to_card(key, values) + end + end CARDS = {} end
xaviershay/dominion-solitaire
5f54ec85f9cf25e14ee52f24b374a2187c61d06c
Refactor card type checking
diff --git a/lib/dominion/card.rb b/lib/dominion/card.rb new file mode 100644 index 0000000..7d0e09e --- /dev/null +++ b/lib/dominion/card.rb @@ -0,0 +1,7 @@ +module Dominion + module Card + def type?(card, type) + [*card[:type]].include?(type) + end + end +end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 6360f53..5711e8e 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,160 +1,162 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' +require 'dominion/card' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board + include Dominion::Card attr_accessor :engine, :cards, :turn def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| - x[:type] == :treasure + type?(x, :treasure) }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def step skip = false if self.prompt.nil? - if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } + if player[:actions] > 0 && player[:hand].detect {|x| type?(x, :action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => Input::Autocomplete.cards {|card| - [*card[:type]].include?(:action) && player[:hand].include?(card) + type?(card, :action) && player[:hand].include?(card) }[self], :color => :green_back, :accept => accept( :accept => lambda {|input| play_card(player, input) }, :decline => lambda {|input| player[:actions] = 0 } ) } elsif player[:buys] > 0 # TODO: option to skip copper buys self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, :accept => accept( :accept => lambda {|input| buy_card(board, player, input) }, :decline => lambda {|input| player[:buys] = 0 } ) } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end def accept(config) lambda {|input| self.prompt = nil if input config[:accept][input] else config[:decline][input] end } end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
d24208c72c126548c9f66c5c740bdc29f8ab178d
Refactor #step
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index e3f8904..6360f53 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,157 +1,160 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => Input::Autocomplete.cards {|card| [*card[:type]].include?(:action) && player[:hand].include?(card) }[self], :color => :green_back, - :accept => lambda {|input| - self.prompt = nil - if input - play_card(player, input) - else - player[:actions] = 0 - end - } + :accept => accept( + :accept => lambda {|input| play_card(player, input) }, + :decline => lambda {|input| player[:actions] = 0 } + ) } elsif player[:buys] > 0 # TODO: option to skip copper buys self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => Input::Autocomplete.cards {|card| card[:cost] <= treasure(player) }[self], :color => :magenta_back, - :accept => lambda {|input| - self.prompt = nil - if input - buy_card(board, player, input) - else - player[:buys] = 0 - end - } + :accept => accept( + :accept => lambda {|input| buy_card(board, player, input) }, + :decline => lambda {|input| player[:buys] = 0 } + ) } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end + + def accept(config) + lambda {|input| + self.prompt = nil + if input + config[:accept][input] + else + config[:decline][input] + end + } + end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
c0c190b14390fe1d44de617a1f625015fffe7434
Keep refactoring autocomplete
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 73fc4d6..e3f8904 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,173 +1,157 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) self.prompt && self.prompt[:autocomplete][:card_active][card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY self.prompt = { :prompt => "action (#{player[:actions]} left)?", - :autocomplete => { - :card_active => lambda {|card| - [*card[:type]].include?(:action) && player[:hand].include?(card) - }, - :strategy => lambda {|input| - suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - prompt[:autocomplete][:card_active][x] && x[:name] =~ /^#{input}/i - } - suggest ? suggest[:name] : nil - } - }, + :autocomplete => Input::Autocomplete.cards {|card| + [*card[:type]].include?(:action) && player[:hand].include?(card) + }[self], :color => :green_back, :accept => lambda {|input| self.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", - :autocomplete => { - :card_active => lambda {|card| - card[:cost] <= treasure(player) - }, - :strategy => lambda {|input| - suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - prompt[:autocomplete][:card_active][x] && x[:name] =~ /^#{Regexp.escape(input)}/i - } - suggest ? suggest[:name] : nil - } - }, + :autocomplete => Input::Autocomplete.cards {|card| + card[:cost] <= treasure(player) + }[self], :color => :magenta_back, :accept => lambda {|input| self.prompt = nil if input buy_card(board, player, input) else player[:buys] = 0 end } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/input.rb b/lib/dominion/input.rb index f52cdcb..990f760 100644 --- a/lib/dominion/input.rb +++ b/lib/dominion/input.rb @@ -1,77 +1,91 @@ module Dominion class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.prompt = { :prompt => opts[:prompt][game, inputs], :autocomplete => opts[:strategy][game], :accept => lambda {|input| if input inputs << input existing = game.prompt game.prompt = nil opts[:each].call(game, input) if opts[:each] unless game.prompt || (opts[:max] && inputs.length >= opts[:max]) game.prompt = existing game.prompt[:prompt] = opts[:prompt].call(game, inputs) end else if !opts[:min] || inputs.length >= opts[:min] game.prompt = nil end end if opts[:after] && game.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete + def self.cards(&match_func) + lambda {|game| { + :card_active => lambda {|card| + match_func.call(card) + }, + :strategy => lambda {|input| + suggest = input.length == 0 ? nil : game.board.map(&:first).detect {|x| + match_func.call(x) && x[:name] =~ /^#{input}/i + } + suggest ? suggest[:name] : nil + } + }} + end + def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| { :card_active => lambda {|card| match_func[card] }, :strategy => lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| { :card_active => lambda {|card| match_func[card] }, :strategy => lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } } end def self.boolean lambda {|game| { :card_active => lambda {|card| false }, :strategy => lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } } end end end end
xaviershay/dominion-solitaire
8f8b91d33bc36524a21755ff53bd42f7d3a3d752
Refactor the autocomplete
diff --git a/lib/dominion/cards/adventurer.rb b/lib/dominion/cards/adventurer.rb index 3ad29b4..5f95bec 100644 --- a/lib/dominion/cards/adventurer.rb +++ b/lib/dominion/cards/adventurer.rb @@ -1,35 +1,38 @@ Dominion::CARDS[:adventurer] = { :type => :action, :cost => 6, :description => 'Reveal until 2T revealed: T to hand, rest to discard', :behaviour => lambda {|game, card| player = game.player revealed = [] treasure = lambda { revealed.select {|x| [*x[:type]].include?(:treasure) } } while treasure[].size < 2 && !(player[:deck] + player[:discard]).empty? game.reveal_card(game.player).tap do |c| revealed << c if c end end game.prompt = { :prompt => "Press enter to continue", - :autocomplete => lambda {|input| nil }, + :autocomplete => { + :strategy => lambda {|input| nil }, + :card_active => lambda {|input| false } + }, :accept => lambda {|input| game.prompt = nil treasure[].each do |t| game.move_card(t, player[:revealed], player[:hand]) revealed.delete_at(revealed.index(t)) end revealed.each do |c| game.move_card(c, player[:revealed], player[:discard]) end } } } } diff --git a/lib/dominion/cards/library.rb b/lib/dominion/cards/library.rb index bd9c482..ceeb454 100644 --- a/lib/dominion/cards/library.rb +++ b/lib/dominion/cards/library.rb @@ -1,35 +1,38 @@ Dominion::CARDS[:library] = { :type => :action, :cost => 5, :description => 'Draw to 7 cards, discard actions as they are drawn', :behaviour => lambda {|game, card| player = game.player revealed = [] non_action = lambda { revealed.reject {|x| [*x[:type]].include?(:action) } } while (player[:hand] + non_action[]).length < 7 && !(player[:deck] + player[:discard]).empty? game.reveal_card(player).tap do |c| revealed << c if c end end game.prompt = { :prompt => "Press enter to continue", - :autocomplete => lambda {|input| nil }, + :autocomplete => { + :strategy => lambda {|input| nil }, + :card_active => lambda {|input| false } + }, :accept => lambda {|input| game.prompt = nil non_action[].each do |t| game.move_card(t, player[:revealed], player[:hand]) revealed.delete_at(revealed.index(t)) end revealed.each do |c| game.move_card(c, player[:revealed], player[:discard]) end } } } } diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 32a7928..73fc4d6 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,175 +1,173 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board - attr_accessor :engine, :cards, :turn, :card_active + attr_accessor :engine, :cards, :turn def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) - (self.card_active || proc { false })[card] + self.prompt && self.prompt[:autocomplete][:card_active][card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY - self.card_active = lambda {|card| - [*card[:type]].include?(:action) && player[:hand].include?(card) - } self.prompt = { - :prompt => "action (#{player[:actions]} left)?", - :completions => lambda {|card| - [*card[:type]].include?(:action) && player[:hand].include?(card) - }, - :autocomplete => lambda {|input| - suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - prompt[:completions][x] && x[:name] =~ /^#{input}/i + :prompt => "action (#{player[:actions]} left)?", + :autocomplete => { + :card_active => lambda {|card| + [*card[:type]].include?(:action) && player[:hand].include?(card) + }, + :strategy => lambda {|input| + suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| + prompt[:autocomplete][:card_active][x] && x[:name] =~ /^#{input}/i + } + suggest ? suggest[:name] : nil } - suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| self.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys - self.card_active = lambda {|card| - card[:cost] <= treasure(player) - } self.prompt = { - :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", - :completions => lambda {|card| - card[:cost] <= treasure(player) - }, - :autocomplete => lambda {|input| - suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - prompt[:completions][x] && x[:name] =~ /^#{Regexp.escape(input)}/i + :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", + :autocomplete => { + :card_active => lambda {|card| + card[:cost] <= treasure(player) + }, + :strategy => lambda {|input| + suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| + prompt[:autocomplete][:card_active][x] && x[:name] =~ /^#{Regexp.escape(input)}/i + } + suggest ? suggest[:name] : nil } - suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| self.prompt = nil if input buy_card(board, player, input) else player[:buys] = 0 end } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/input.rb b/lib/dominion/input.rb index 04df4f8..f52cdcb 100644 --- a/lib/dominion/input.rb +++ b/lib/dominion/input.rb @@ -1,68 +1,77 @@ module Dominion class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.prompt = { - :prompt => opts[:prompt].call(game, inputs), - :autocomplete => opts[:strategy].call(game), + :prompt => opts[:prompt][game, inputs], + :autocomplete => opts[:strategy][game], :accept => lambda {|input| if input inputs << input existing = game.prompt game.prompt = nil opts[:each].call(game, input) if opts[:each] unless game.prompt || (opts[:max] && inputs.length >= opts[:max]) game.prompt = existing game.prompt[:prompt] = opts[:prompt].call(game, inputs) end else if !opts[:min] || inputs.length >= opts[:min] game.prompt = nil end end if opts[:after] && game.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| - lambda {|input| - suggest = input.length == 0 ? nil : game.board.detect {|x| - x[0][:name] =~ /^#{input}/i && match_func[x[0]] + { + :card_active => lambda {|card| match_func[card] }, + :strategy => lambda {|input| + suggest = input.length == 0 ? nil : game.board.detect {|x| + x[0][:name] =~ /^#{input}/i && match_func[x[0]] + } + suggest ? suggest[0][:name] : nil } - suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| - lambda {|input| - suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| - x[:name] =~ /^#{input}/i && match_func[x] + { + :card_active => lambda {|card| match_func[card] }, + :strategy => lambda {|input| + suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| + x[:name] =~ /^#{input}/i && match_func[x] + } + suggest ? suggest[:name] : nil } - suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| - lambda {|input| - %w(Y N).detect {|x| x == input.upcase } || nil + { + :card_active => lambda {|card| false }, + :strategy => lambda {|input| + %w(Y N).detect {|x| x == input.upcase } || nil + } } } end end end end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 848a79c..e106cbc 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,298 +1,298 @@ require 'ffi-ncurses' require 'dominion/engine' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses attr_accessor :input_buffer def setup super self.input_buffer = '' initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(game, ctx) ch = wgetch(ctx[:input_window]) if game.prompt case ch when 10 - autocompleted = game.prompt[:autocomplete][input_buffer] + autocompleted = game.prompt[:autocomplete][:strategy][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) game.prompt[:accept][autocompleted] end self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if game.card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if game.card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if game.prompt #print_with_color[:yellow_back, "%-80s" % ""] - suggest = game.prompt[:autocomplete][input_buffer].to_s + suggest = game.prompt[:autocomplete][:strategy][input_buffer].to_s print_with_color[game.prompt[:color] || :yellow_back, "%s %s" % [ game.prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 2ef8847..8e1c3c0 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,93 +1,89 @@ require 'spec_helper' describe Dominion::Game do subject do game_with_cards(:estate, :copper, :smithy, :chancellor) end describe '#step' do it 'does not blow up' do subject.step end describe 'when no prompt' do describe 'when actions available' do describe 'when autoplay actions in hand' do end describe 'when actions in hand' do before do hand cards(:copper, 1) + cards(:smithy, 1) subject.step end it { should have_prompt_with_autocomplete :actions_in_hand } end end describe 'when no actions left and buys available' do before do player[:actions] = 0 subject.step end it { should have_prompt_with_autocomplete :buyable_cards } end describe 'with no actions and no buys' do before do deck cards(:estate, 5) hand cards(:copper, 1) played cards(:smithy, 1) player[:actions] = player[:buys] = 0 subject.step end it('resets buys') { player[:buys ].should == 1 } it('resets actions') { player[:actions].should == 1 } it('resets gold') { player[:gold ].should == 0 } it('increments turn') { subject.turn.should == 2 } it 'moves hand and player to discard' do discard.should have_cards cards(:copper, 1) + cards(:smithy, 1) end it 'empties played' do played.should == [] end it 'draws five new cards' do hand.should have_cards cards(:estate, 5) end end end end describe '#card_active?' do let(:check_card) { card(:copper) } - describe 'when no card_active proc is supplied' do - before do - subject.card_active = nil - end - - specify do - subject.card_active?(check_card).should be_false - end + describe 'when no prompt' do + specify { subject.card_active?(check_card).should be_false } end - describe 'when a card_active proc is supplied' do + describe 'when prompt with autocomplete matching the given card' do before do - subject.card_active = lambda {|card| card[:key] } + subject.prompt = { + :autocomplete => { + :card_active => lambda {|card| card == check_card } + } + } end - specify do - subject.card_active?(check_card).should == check_card[:key] - end + specify { subject.card_active?(check_card).should be_true } end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 844f658..264aa25 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,195 +1,195 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| case autocomplete_strategy when :cards_in_hand then # TODO: Make this match the :actions_in_hand one game.prompt begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] - game.prompt[:autocomplete]['co'].should == 'Copper' - game.prompt[:autocomplete]['es'].should == nil - game.prompt[:autocomplete]['ce'].should == nil + game.prompt[:autocomplete][:strategy]['co'].should == 'Copper' + game.prompt[:autocomplete][:strategy]['es'].should == nil + game.prompt[:autocomplete][:strategy]['ce'].should == nil ensure game.player = old_player end when :actions_in_hand then to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } to_not_match = game.player[:hand] - to_match to_match.each do |card| - game.prompt[:autocomplete][card[:name][0..2]].should == card[:name] - game.card_active[card].should == true + game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] + game.prompt[:autocomplete][:card_active][card].should == true end to_not_match.each do |card| - game.prompt[:autocomplete][card[:name][0..2]].should == nil - game.card_active[card].should == false + game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil + game.prompt[:autocomplete][:card_active][card].should == false end when :buyable_cards then cards = game.board.map(&:first) to_match = cards.select {|x| x[:cost] <= game.treasure(game.player) } to_not_match = cards - to_match to_match.each do |card| - game.prompt[:autocomplete][card[:name][0..2]].should == card[:name] - game.card_active[card].should == true + game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == card[:name] + game.prompt[:autocomplete][:card_active][card].should == true end to_not_match.each do |card| - game.prompt[:autocomplete][card[:name][0..2]].should == nil - game.card_active[card].should == false + game.prompt[:autocomplete][:strategy][card[:name][0..2]].should == nil + game.prompt[:autocomplete][:card_active][card].should == false end end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) game.engine = Dominion::Engine.new end end def game @game end def card(key) subject unless @game @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt - prompt[:accept][prompt[:autocomplete][key]] if prompt + prompt[:accept][prompt[:autocomplete][:strategy][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player subject unless @game @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end def log(*args) end
xaviershay/dominion-solitaire
8723cf49557b4b6c78e5ed0405dc3e085cd340be
Start moving around autocomplete
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index eae27dc..32a7928 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,169 +1,175 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn, :card_active def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) (self.card_active || proc { false })[card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end return if skip # --- END AUTOPLAY self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card) } self.prompt = { :prompt => "action (#{player[:actions]} left)?", + :completions => lambda {|card| + [*card[:type]].include?(:action) && player[:hand].include?(card) + }, :autocomplete => lambda {|input| - suggest = input.length == 0 ? nil : player[:hand].detect {|x| - [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i + suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| + prompt[:completions][x] && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| self.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys self.card_active = lambda {|card| card[:cost] <= treasure(player) } self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", + :completions => lambda {|card| + card[:cost] <= treasure(player) + }, :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i + prompt[:completions][x] && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| + self.prompt = nil if input buy_card(board, player, input) else player[:buys] = 0 end - self.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
072659cff450e01aa5c11f5b67d6d1f9974bf2cd
Spec cleanup
diff --git a/lib/dominion/player.rb b/lib/dominion/player.rb index 8425b29..dc55cb1 100644 --- a/lib/dominion/player.rb +++ b/lib/dominion/player.rb @@ -1,141 +1,144 @@ module Dominion module Player def player=(value) @player = value end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :trashed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] + + # Following three are for logging only player[:discarded] = [] player[:trashed] = [] player[:bought] = [] + 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 03e82db..2ef8847 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,69 +1,93 @@ require 'spec_helper' describe Dominion::Game do subject do - game_with_cards(:copper, :smithy, :chancellor) + game_with_cards(:estate, :copper, :smithy, :chancellor) end describe '#step' do it 'does not blow up' do subject.step end describe 'when no prompt' do describe 'when actions available' do describe 'when autoplay actions in hand' do end describe 'when actions in hand' do before do hand cards(:copper, 1) + cards(:smithy, 1) subject.step end it { should have_prompt_with_autocomplete :actions_in_hand } end end describe 'when no actions left and buys available' do before do player[:actions] = 0 subject.step end it { should have_prompt_with_autocomplete :buyable_cards } end describe 'with no actions and no buys' do - it 'cleans up and progresses to the next turn' do + before do + deck cards(:estate, 5) + hand cards(:copper, 1) + played cards(:smithy, 1) + + player[:actions] = player[:buys] = 0 + + subject.step + end + + it('resets buys') { player[:buys ].should == 1 } + it('resets actions') { player[:actions].should == 1 } + it('resets gold') { player[:gold ].should == 0 } + it('increments turn') { subject.turn.should == 2 } + + it 'moves hand and player to discard' do + discard.should have_cards cards(:copper, 1) + cards(:smithy, 1) + end + + it 'empties played' do + played.should == [] + end + + it 'draws five new cards' do + hand.should have_cards cards(:estate, 5) end end end end describe '#card_active?' do let(:check_card) { card(:copper) } describe 'when no card_active proc is supplied' do before do subject.card_active = nil end specify do subject.card_active?(check_card).should be_false end end describe 'when a card_active proc is supplied' do before do subject.card_active = lambda {|card| card[:key] } end specify do subject.card_active?(check_card).should == check_card[:key] end end end end
xaviershay/dominion-solitaire
86e0632ee56fca50d6fc0646a78cbb33ec999a2b
Spec for buy prompt
diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 430cd52..03e82db 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,67 +1,69 @@ require 'spec_helper' describe Dominion::Game do subject do game_with_cards(:copper, :smithy, :chancellor) end describe '#step' do it 'does not blow up' do subject.step end describe 'when no prompt' do describe 'when actions available' do describe 'when autoplay actions in hand' do end describe 'when actions in hand' do before do hand cards(:copper, 1) + cards(:smithy, 1) subject.step end it { should have_prompt_with_autocomplete :actions_in_hand } end end - describe 'when buys available' do - it 'marks all buyable cards active' do - end + describe 'when no actions left and buys available' do + before do + player[:actions] = 0 - it 'prompts to select a card to buy' do + subject.step end + + it { should have_prompt_with_autocomplete :buyable_cards } end describe 'with no actions and no buys' do it 'cleans up and progresses to the next turn' do end end end end describe '#card_active?' do let(:check_card) { card(:copper) } describe 'when no card_active proc is supplied' do before do subject.card_active = nil end specify do subject.card_active?(check_card).should be_false end end describe 'when a card_active proc is supplied' do before do subject.card_active = lambda {|card| card[:key] } end specify do subject.card_active?(check_card).should == check_card[:key] end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ba1e122..844f658 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,178 +1,195 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| case autocomplete_strategy when :cards_in_hand then # TODO: Make this match the :actions_in_hand one game.prompt begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] game.prompt[:autocomplete]['co'].should == 'Copper' game.prompt[:autocomplete]['es'].should == nil game.prompt[:autocomplete]['ce'].should == nil ensure game.player = old_player end when :actions_in_hand then to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } to_not_match = game.player[:hand] - to_match to_match.each do |card| game.prompt[:autocomplete][card[:name][0..2]].should == card[:name] game.card_active[card].should == true end to_not_match.each do |card| game.prompt[:autocomplete][card[:name][0..2]].should == nil game.card_active[card].should == false end + + when :buyable_cards then + cards = game.board.map(&:first) + to_match = cards.select {|x| x[:cost] <= game.treasure(game.player) } + to_not_match = cards - to_match + + to_match.each do |card| + game.prompt[:autocomplete][card[:name][0..2]].should == card[:name] + game.card_active[card].should == true + end + + to_not_match.each do |card| + game.prompt[:autocomplete][card[:name][0..2]].should == nil + game.card_active[card].should == false + end + end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) game.engine = Dominion::Engine.new end end def game @game end def card(key) subject unless @game @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player + subject unless @game @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end def log(*args) end
xaviershay/dominion-solitaire
b0a3075cc25b04acac3c29a516dacd6e606c29c4
Start speccing #step
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 62b915a..eae27dc 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,164 +1,169 @@ require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn, :card_active def initialize self.cards = {} self.turn = 1 self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) (self.card_active || proc { false })[card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def step skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } + # --- AUTOPLAY SECTION autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end - next if skip + return if skip + # --- END AUTOPLAY - self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} + self.card_active = lambda {|card| + [*card[:type]].include?(:action) && player[:hand].include?(card) + } self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| self.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys self.card_active = lambda {|card| card[:cost] <= treasure(player) } self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end self.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end + def run cleanup(board, player) engine.setup while true step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index fd88ba8..430cd52 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,37 +1,67 @@ require 'spec_helper' describe Dominion::Game do subject do - game_with_cards(:copper) + game_with_cards(:copper, :smithy, :chancellor) end describe '#step' do it 'does not blow up' do subject.step end + + describe 'when no prompt' do + describe 'when actions available' do + describe 'when autoplay actions in hand' do + end + + describe 'when actions in hand' do + before do + hand cards(:copper, 1) + cards(:smithy, 1) + + subject.step + end + + it { should have_prompt_with_autocomplete :actions_in_hand } + end + end + + describe 'when buys available' do + it 'marks all buyable cards active' do + end + + it 'prompts to select a card to buy' do + end + end + + describe 'with no actions and no buys' do + it 'cleans up and progresses to the next turn' do + end + end + end end describe '#card_active?' do let(:check_card) { card(:copper) } describe 'when no card_active proc is supplied' do before do subject.card_active = nil end specify do subject.card_active?(check_card).should be_false end end describe 'when a card_active proc is supplied' do before do subject.card_active = lambda {|card| card[:key] } end specify do subject.card_active?(check_card).should == check_card[:key] end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4b9d94a..ba1e122 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,160 +1,178 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| - game.prompt - # TODO: Check auto complete - begin - old_player = game.player.dup - - game.player[:deck] = [game.card(:estate)] - game.player[:hand] = [game.card(:copper)] - game.prompt[:autocomplete]['co'].should == 'Copper' - game.prompt[:autocomplete]['es'].should == nil - game.prompt[:autocomplete]['ce'].should == nil - ensure - game.player = old_player + case autocomplete_strategy + when :cards_in_hand then + # TODO: Make this match the :actions_in_hand one + game.prompt + begin + old_player = game.player.dup + + game.player[:deck] = [game.card(:estate)] + game.player[:hand] = [game.card(:copper)] + game.prompt[:autocomplete]['co'].should == 'Copper' + game.prompt[:autocomplete]['es'].should == nil + game.prompt[:autocomplete]['ce'].should == nil + ensure + game.player = old_player + end + + when :actions_in_hand then + to_match = game.player[:hand].select {|x| [*x[:type]].include?(:action) } + to_not_match = game.player[:hand] - to_match + + to_match.each do |card| + game.prompt[:autocomplete][card[:name][0..2]].should == card[:name] + game.card_active[card].should == true + end + + to_not_match.each do |card| + game.prompt[:autocomplete][card[:name][0..2]].should == nil + game.card_active[card].should == false + end end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) game.engine = Dominion::Engine.new end end def game @game end def card(key) + subject unless @game @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end def log(*args) end
xaviershay/dominion-solitaire
7e7266569bfd0d36c8c8d517457ee994ec892a26
Refactor out the UI engine and the #run method so I can start speccing the run logic
diff --git a/lib/dominion/engine.rb b/lib/dominion/engine.rb index 53a5600..b40b1b4 100644 --- a/lib/dominion/engine.rb +++ b/lib/dominion/engine.rb @@ -1,15 +1,15 @@ module Dominion class Engine def setup end def draw(game, ctx = {}) end - def step(ctx) + def step(game, ctx) end def finalize end end end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 4eb297f..62b915a 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,162 +1,164 @@ -require 'dominion/ui' +require 'dominion/engine' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn, :card_active def initialize self.cards = {} self.turn = 1 - self.engine = Dominion::UI::NCurses.new + self.engine = Dominion::Engine.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) (self.card_active || proc { false })[card] end def prompt @prompt end def prompt=(value) @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end - def run - cleanup(board, player) - engine.setup - running = true - - while running - skip = false - if self.prompt.nil? - if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } - autoplay = [:village, :market, :laboratory] - unless player[:hand].detect {|x| x[:key] == :throne_room } - while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } - play_card(player, to_play[:name]) - skip = true - end + def step + skip = false + if self.prompt.nil? + if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } + autoplay = [:village, :market, :laboratory] + unless player[:hand].detect {|x| x[:key] == :throne_room } + while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } + play_card(player, to_play[:name]) + skip = true end + end - next if skip - - self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} - self.prompt = { - :prompt => "action (#{player[:actions]} left)?", - :autocomplete => lambda {|input| - suggest = input.length == 0 ? nil : player[:hand].detect {|x| - [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i - } - suggest ? suggest[:name] : nil - }, - :color => :green_back, - :accept => lambda {|input| - self.prompt = nil - if input - play_card(player, input) - else - player[:actions] = 0 - end + next if skip + + self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} + self.prompt = { + :prompt => "action (#{player[:actions]} left)?", + :autocomplete => lambda {|input| + suggest = input.length == 0 ? nil : player[:hand].detect {|x| + [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } + suggest ? suggest[:name] : nil + }, + :color => :green_back, + :accept => lambda {|input| + self.prompt = nil + if input + play_card(player, input) + else + player[:actions] = 0 + end } - elsif player[:buys] > 0 # TODO: option to skip copper buys - self.card_active = lambda {|card| - card[:cost] <= treasure(player) - } - self.prompt = { - :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", - :autocomplete => lambda {|input| - suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i - } - suggest ? suggest[:name] : nil - }, - :color => :magenta_back, - :accept => lambda {|input| - if input - buy_card(board, player, input) - else - player[:buys] = 0 - end - self.prompt = nil + } + elsif player[:buys] > 0 # TODO: option to skip copper buys + self.card_active = lambda {|card| + card[:cost] <= treasure(player) + } + self.prompt = { + :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", + :autocomplete => lambda {|input| + suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| + x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } + suggest ? suggest[:name] : nil + }, + :color => :magenta_back, + :accept => lambda {|input| + if input + buy_card(board, player, input) + else + player[:buys] = 0 + end + self.prompt = nil } - else - # Run the cleanup phase - cleanup(board, player) - skip = true - @turn += 1 - end + } + else + # Run the cleanup phase + cleanup(board, player) + skip = true + @turn += 1 end + end - unless skip - ctx = engine.draw(self) - engine.step(self, ctx) - end + unless skip + ctx = engine.draw(self) + engine.step(self, ctx) + end + end + def run + cleanup(board, player) + engine.setup + + while true + step end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/run.rb b/lib/run.rb index 01e878a..266ded0 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,20 +1,22 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) def log(message) @log ||= File.open('debug.log', 'a') @log.puts message @log.flush end require 'dominion/game' +require 'dominion/ui' game = Dominion::Game.new if ARGV[0] board = File.open(ARGV[0]).read.lines.reject {|x| x[0] == '#'[0] }.map {|x| x.chomp.downcase.tr(' ', '_').to_sym } board += game.default_cards game.load_cards(*board) else game.load_all_cards end +game.engine = Dominion::UI::NCurses.new game.run diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 202e7ee..fd88ba8 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,31 +1,37 @@ require 'spec_helper' describe Dominion::Game do subject do game_with_cards(:copper) end + describe '#step' do + it 'does not blow up' do + subject.step + end + end + describe '#card_active?' do let(:check_card) { card(:copper) } describe 'when no card_active proc is supplied' do before do subject.card_active = nil end specify do subject.card_active?(check_card).should be_false end end describe 'when a card_active proc is supplied' do before do subject.card_active = lambda {|card| card[:key] } end specify do subject.card_active?(check_card).should == check_card[:key] end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 107050d..4b9d94a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,156 +1,160 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| game.prompt # TODO: Check auto complete begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] game.prompt[:autocomplete]['co'].should == 'Copper' game.prompt[:autocomplete]['es'].should == nil game.prompt[:autocomplete]['ce'].should == nil ensure game.player = old_player end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) + game.engine = Dominion::Engine.new end end def game @game end def card(key) @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end + +def log(*args) +end
xaviershay/dominion-solitaire
3d634ff35352ec7deed1cd3416a30bea0d7625dc
Move input buffer into ncurses UI
diff --git a/lib/dominion/engine.rb b/lib/dominion/engine.rb index 52d91c8..53a5600 100644 --- a/lib/dominion/engine.rb +++ b/lib/dominion/engine.rb @@ -1,16 +1,15 @@ module Dominion class Engine def setup - self.input_buffer = '' end def draw(game, ctx = {}) end def step(ctx) end def finalize end end end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index dad6f5f..848a79c 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,296 +1,298 @@ require 'ffi-ncurses' require 'dominion/engine' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses attr_accessor :input_buffer def setup super + self.input_buffer = '' + initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(game, ctx) ch = wgetch(ctx[:input_window]) if game.prompt case ch when 10 autocompleted = game.prompt[:autocomplete][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) game.prompt[:accept][autocompleted] end self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if game.card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if game.card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if game.prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = game.prompt[:autocomplete][input_buffer].to_s print_with_color[game.prompt[:color] || :yellow_back, "%s %s" % [ game.prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end end
xaviershay/dominion-solitaire
6737e557067519ab16dd545d82c7c5d4d60fe3d9
Move prompt out of engine
diff --git a/lib/dominion/engine.rb b/lib/dominion/engine.rb index abac202..52d91c8 100644 --- a/lib/dominion/engine.rb +++ b/lib/dominion/engine.rb @@ -1,19 +1,16 @@ module Dominion class Engine - attr_accessor :prompt - def setup - self.prompt = nil self.input_buffer = '' end def draw(game, ctx = {}) end def step(ctx) end def finalize end end end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index dc75a16..4eb297f 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,162 +1,162 @@ require 'dominion/ui' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn, :card_active def initialize self.cards = {} self.turn = 1 self.engine = Dominion::UI::NCurses.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) (self.card_active || proc { false })[card] end def prompt - engine.prompt + @prompt end def prompt=(value) - engine.prompt = value + @prompt = value end def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def run cleanup(board, player) engine.setup running = true while running skip = false if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| self.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys self.card_active = lambda {|card| card[:cost] <= treasure(player) } self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end self.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index b162f95..dad6f5f 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,296 +1,296 @@ require 'ffi-ncurses' require 'dominion/engine' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses attr_accessor :input_buffer def setup super initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(game, ctx) ch = wgetch(ctx[:input_window]) - if prompt + if game.prompt case ch when 10 - autocompleted = prompt[:autocomplete][input_buffer] + autocompleted = game.prompt[:autocomplete][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) - prompt[:accept][autocompleted] + game.prompt[:accept][autocompleted] end self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if game.card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if game.card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end - if prompt + if game.prompt #print_with_color[:yellow_back, "%-80s" % ""] - suggest = prompt[:autocomplete][input_buffer].to_s + suggest = game.prompt[:autocomplete][input_buffer].to_s - print_with_color[prompt[:color] || :yellow_back, "%s %s" % [ - prompt[:prompt], + print_with_color[game.prompt[:color] || :yellow_back, "%s %s" % [ + game.prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end end
xaviershay/dominion-solitaire
1b788be544bda8ec46b256a6af2856b7dd38ee31
Demeter up game.engine.prompt
diff --git a/lib/dominion/cards/adventurer.rb b/lib/dominion/cards/adventurer.rb index 46be563..3ad29b4 100644 --- a/lib/dominion/cards/adventurer.rb +++ b/lib/dominion/cards/adventurer.rb @@ -1,35 +1,35 @@ Dominion::CARDS[:adventurer] = { :type => :action, :cost => 6, :description => 'Reveal until 2T revealed: T to hand, rest to discard', :behaviour => lambda {|game, card| player = game.player revealed = [] treasure = lambda { revealed.select {|x| [*x[:type]].include?(:treasure) } } while treasure[].size < 2 && !(player[:deck] + player[:discard]).empty? game.reveal_card(game.player).tap do |c| revealed << c if c end end - game.engine.prompt = { + game.prompt = { :prompt => "Press enter to continue", :autocomplete => lambda {|input| nil }, :accept => lambda {|input| - game.engine.prompt = nil + game.prompt = nil treasure[].each do |t| game.move_card(t, player[:revealed], player[:hand]) revealed.delete_at(revealed.index(t)) end revealed.each do |c| game.move_card(c, player[:revealed], player[:discard]) end } } } } diff --git a/lib/dominion/cards/chancellor.rb b/lib/dominion/cards/chancellor.rb index 9836bb9..05f139a 100644 --- a/lib/dominion/cards/chancellor.rb +++ b/lib/dominion/cards/chancellor.rb @@ -1,19 +1,19 @@ Dominion::CARDS[:chancellor] = { :type => :action, :cost => 3, :gold => 2, :behaviour => lambda {|game, card| - game.engine.prompt = { + game.prompt = { :prompt => "Discard your deck (y/N)?", :autocomplete => Dominion::Input::Autocomplete.boolean[game], :accept => lambda {|input| if input == 'Y' game.player[:discard] += game.player[:deck] game.player[:deck] = [] end - game.engine.prompt = nil + game.prompt = nil } } } } diff --git a/lib/dominion/cards/library.rb b/lib/dominion/cards/library.rb index 33832eb..bd9c482 100644 --- a/lib/dominion/cards/library.rb +++ b/lib/dominion/cards/library.rb @@ -1,35 +1,35 @@ Dominion::CARDS[:library] = { :type => :action, :cost => 5, :description => 'Draw to 7 cards, discard actions as they are drawn', :behaviour => lambda {|game, card| player = game.player revealed = [] non_action = lambda { revealed.reject {|x| [*x[:type]].include?(:action) } } while (player[:hand] + non_action[]).length < 7 && !(player[:deck] + player[:discard]).empty? game.reveal_card(player).tap do |c| revealed << c if c end end - game.engine.prompt = { + game.prompt = { :prompt => "Press enter to continue", :autocomplete => lambda {|input| nil }, :accept => lambda {|input| - game.engine.prompt = nil + game.prompt = nil non_action[].each do |t| game.move_card(t, player[:revealed], player[:hand]) revealed.delete_at(revealed.index(t)) end revealed.each do |c| game.move_card(c, player[:revealed], player[:discard]) end } } } } diff --git a/lib/dominion/cards/moneylender.rb b/lib/dominion/cards/moneylender.rb index 51a695a..094c7f2 100644 --- a/lib/dominion/cards/moneylender.rb +++ b/lib/dominion/cards/moneylender.rb @@ -1,21 +1,21 @@ Dominion::CARDS[:moneylender] = { :type => :action, :cost => 4, :description => 'Trash a copper, +3T', :behaviour => lambda {|game, card| if game.player[:hand].detect {|x| x[:key] == :copper } - game.engine.prompt = { + game.prompt = { :prompt => "Trash a copper (N/y)?", :autocomplete => Dominion::Input::Autocomplete.boolean[game], :accept => lambda {|input| if input == 'Y' game.move_card(:copper, game.player[:hand], game.player[:trash]) game.player[:gold] += 3 end - game.engine.prompt = nil + game.prompt = nil } } end } } diff --git a/lib/dominion/cards/spy.rb b/lib/dominion/cards/spy.rb index c7c81dd..42a1b00 100644 --- a/lib/dominion/cards/spy.rb +++ b/lib/dominion/cards/spy.rb @@ -1,24 +1,24 @@ Dominion::CARDS[:spy] = { :type => [:action, :attack], :cost => 4, :cards => 1, :actions => 1, :description => 'All reveal top card of deck, you discard or put back', :behaviour => lambda {|game, card| card = game.reveal_card(game.player) - game.engine.prompt = { + game.prompt = { :prompt => "Discard #{card[:name]} (y/N)?", :autocomplete => Dominion::Input::Autocomplete.boolean[game], :accept => lambda {|input| if input == 'Y' game.move_card(card, game.player[:revealed], game.player[:discard]) else game.move_card(card, game.player[:revealed], game.player[:deck]) end - game.engine.prompt = nil + game.prompt = nil } } if card } } diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 23317b9..dc75a16 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,156 +1,162 @@ require 'dominion/ui' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn, :card_active def initialize self.cards = {} self.turn = 1 self.engine = Dominion::UI::NCurses.new end # An active card is one that can be interacted with. They are generally # highlighted in the UI. # # card - a hash describing a card def card_active?(card) (self.card_active || proc { false })[card] end + def prompt + engine.prompt + end + + def prompt=(value) + engine.prompt = value + end + def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def run cleanup(board, player) engine.setup running = true while running skip = false - if engine.prompt.nil? + if self.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} - engine.prompt = { + self.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| - engine.prompt = nil + self.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys self.card_active = lambda {|card| card[:cost] <= treasure(player) } - engine.prompt = { + self.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end - engine.prompt = nil + self.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(self, ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) - prompt = engine.prompt - if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/input.rb b/lib/dominion/input.rb index 7f1efe3..04df4f8 100644 --- a/lib/dominion/input.rb +++ b/lib/dominion/input.rb @@ -1,68 +1,68 @@ module Dominion class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] - game.engine.prompt = { + game.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input - existing = game.engine.prompt - game.engine.prompt = nil + existing = game.prompt + game.prompt = nil opts[:each].call(game, input) if opts[:each] - unless game.engine.prompt || (opts[:max] && inputs.length >= opts[:max]) - game.engine.prompt = existing - game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) + unless game.prompt || (opts[:max] && inputs.length >= opts[:max]) + game.prompt = existing + game.prompt[:prompt] = opts[:prompt].call(game, inputs) end else if !opts[:min] || inputs.length >= opts[:min] - game.engine.prompt = nil + game.prompt = nil end end - if opts[:after] && game.engine.prompt.nil? + if opts[:after] && game.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c8f5153..107050d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,156 +1,156 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| - game.engine.prompt + game.prompt # TODO: Check auto complete begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] - game.engine.prompt[:autocomplete]['co'].should == 'Copper' - game.engine.prompt[:autocomplete]['es'].should == nil - game.engine.prompt[:autocomplete]['ce'].should == nil + game.prompt[:autocomplete]['co'].should == 'Copper' + game.prompt[:autocomplete]['es'].should == nil + game.prompt[:autocomplete]['ce'].should == nil ensure game.player = old_player end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| - game.engine.prompt + game.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end Spec::Matchers.define :have_stack do |card, number| match do |board| stack = board.detect {|x| x[0][:key] == card } if number stack && stack.length == number else stack end end failure_message_for_should do |board| "expected board #{format_board(board)} to have #{number} x #{card}" end failure_message_for_should_not do |board| "expected board #{format_board(board)} to not have #{card}" end def format_board(board) "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) end end def game @game end def card(key) @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) - prompt = @game.engine.prompt + prompt = @game.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end
xaviershay/dominion-solitaire
fb364e2518fede9ddb7ec8c20b1e0e6b6a2ae9ee
Clean up board spec
diff --git a/spec/board_spec.rb b/spec/board_spec.rb index 261d78d..6c16f3c 100644 --- a/spec/board_spec.rb +++ b/spec/board_spec.rb @@ -1,23 +1,21 @@ require 'spec_helper' describe Dominion::Game do describe 'the initial board' do DB = Dominion::Board subject do - Dominion::Game.new.tap {|game| - game.load_cards(default_card, defined_card) - }.board + game_with_cards(default_card, defined_card).board end include Dominion::Board let(:default_card) { (DB::DEFAULT_CARDS - DB::AMOUNTS.keys)[0] } let(:defined_card) { (DB::DEFAULT_CARDS & DB::AMOUNTS.keys)[0] } let(:unloaded_card) { (DB::DEFAULT_CARDS - DB::AMOUNTS.keys)[1] } it { should have_stack(defined_card, DB::AMOUNTS[defined_card]) } it { should have_stack(default_card, DB::DEFAULT_AMOUNT) } it { should_not have_stack(unloaded_card) } end end
xaviershay/dominion-solitaire
5056130019ecbe1eb6b56d3e5f8194ca20da2d04
Move card_active into Game
diff --git a/lib/dominion/engine.rb b/lib/dominion/engine.rb index 925113b..abac202 100644 --- a/lib/dominion/engine.rb +++ b/lib/dominion/engine.rb @@ -1,19 +1,19 @@ module Dominion class Engine - attr_accessor :prompt, :input_buffer, :card_active + attr_accessor :prompt def setup self.prompt = nil self.input_buffer = '' end def draw(game, ctx = {}) end def step(ctx) end def finalize end end end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 1e91d66..23317b9 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,148 +1,156 @@ require 'dominion/ui' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board - attr_accessor :engine, :cards, :turn + attr_accessor :engine, :cards, :turn, :card_active def initialize self.cards = {} self.turn = 1 self.engine = Dominion::UI::NCurses.new end + # An active card is one that can be interacted with. They are generally + # highlighted in the UI. + # + # card - a hash describing a card + def card_active?(card) + (self.card_active || proc { false })[card] + end + def add_card(key, values) key = key.to_sym cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip - engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} + self.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys - engine.card_active = lambda {|card| + self.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) - engine.step(ctx) + engine.step(self, ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) prompt = engine.prompt if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 7597179..b162f95 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,298 +1,296 @@ require 'ffi-ncurses' require 'dominion/engine' module Dominion; module UI; end; end; class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses + attr_accessor :input_buffer + def setup super initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end - def step(ctx) + def step(game, ctx) ch = wgetch(ctx[:input_window]) if prompt case ch when 10 autocompleted = prompt[:autocomplete][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) prompt[:accept][autocompleted] end self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] - if card_active?(card) + if game.card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' - if card_active?(card) + if game.card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = prompt[:autocomplete][input_buffer].to_s print_with_color[prompt[:color] || :yellow_back, "%s %s" % [ prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end - - def card_active?(card) - (self.card_active || lambda { false }).call(card) - end end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 0fe0159..202e7ee 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,6 +1,31 @@ require 'spec_helper' describe Dominion::Game do - describe '#run' do + subject do + game_with_cards(:copper) + end + + describe '#card_active?' do + let(:check_card) { card(:copper) } + + describe 'when no card_active proc is supplied' do + before do + subject.card_active = nil + end + + specify do + subject.card_active?(check_card).should be_false + end + end + + describe 'when a card_active proc is supplied' do + before do + subject.card_active = lambda {|card| card[:key] } + end + + specify do + subject.card_active?(check_card).should == check_card[:key] + end + end end end
xaviershay/dominion-solitaire
fc0df5d977c135eb5df947eec4b699130ff720db
Start extracting abstract engine
diff --git a/lib/dominion/engine.rb b/lib/dominion/engine.rb new file mode 100644 index 0000000..925113b --- /dev/null +++ b/lib/dominion/engine.rb @@ -0,0 +1,19 @@ +module Dominion + class Engine + attr_accessor :prompt, :input_buffer, :card_active + + def setup + self.prompt = nil + self.input_buffer = '' + end + + def draw(game, ctx = {}) + end + + def step(ctx) + end + + def finalize + end + end +end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 746e9a0..7597179 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,300 +1,298 @@ require 'ffi-ncurses' +require 'dominion/engine' module Dominion; module UI; end; end; -class Dominion::UI::NCurses +class Dominion::UI::NCurses < Dominion::Engine include FFI::NCurses - attr_accessor :prompt, :input_buffer, :card_active - def setup - self.prompt = nil - self.input_buffer = '' + super initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(ctx) ch = wgetch(ctx[:input_window]) if prompt case ch when 10 autocompleted = prompt[:autocomplete][input_buffer] if !(autocompleted == nil && input_buffer.length > 0) prompt[:accept][autocompleted] end self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = prompt[:autocomplete][input_buffer].to_s print_with_color[prompt[:color] || :yellow_back, "%s %s" % [ prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end def card_active?(card) (self.card_active || lambda { false }).call(card) end end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index 7850939..0fe0159 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,4 +1,6 @@ require 'spec_helper' describe Dominion::Game do + describe '#run' do + end end
xaviershay/dominion-solitaire
581543611f989e2ba5e688635972abc2e3134364
Clean up board spec
diff --git a/lib/dominion/board.rb b/lib/dominion/board.rb index 7d7d28d..a2174ac 100644 --- a/lib/dominion/board.rb +++ b/lib/dominion/board.rb @@ -1,31 +1,33 @@ module Dominion + # Methods to populate the initial board. Requires an accessor +cards+ in + # the containing class to contain an array of all the loaded cards module Board DEFAULT_CARDS = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] DEFAULT_AMOUNT = 8 AMOUNTS = { :copper => 60, :silver => 40, :gold => 30 } def board @board ||= begin (card_set & cards.keys).map {|x| card_array(x, AMOUNTS[x] || DEFAULT_AMOUNT) } end end def card_set DEFAULT_CARDS + randomize(cards.keys - DEFAULT_CARDS)[0..9] end def card(key) cards[key] || raise("No card #{key}") end def card_array(key, number) [card(key)] * number end end end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index a0e3d69..1e91d66 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,148 +1,148 @@ require 'dominion/ui' require 'dominion/util' require 'dominion/player' require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player include Dominion::Board attr_accessor :engine, :cards, :turn def initialize self.cards = {} self.turn = 1 self.engine = Dominion::UI::NCurses.new end def add_card(key, values) key = key.to_sym - @cards[key] = add_defaults_to_card(key, values) + cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) prompt = engine.prompt if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/spec/board_spec.rb b/spec/board_spec.rb new file mode 100644 index 0000000..261d78d --- /dev/null +++ b/spec/board_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Dominion::Game do + describe 'the initial board' do + DB = Dominion::Board + + subject do + Dominion::Game.new.tap {|game| + game.load_cards(default_card, defined_card) + }.board + end + + include Dominion::Board + + let(:default_card) { (DB::DEFAULT_CARDS - DB::AMOUNTS.keys)[0] } + let(:defined_card) { (DB::DEFAULT_CARDS & DB::AMOUNTS.keys)[0] } + let(:unloaded_card) { (DB::DEFAULT_CARDS - DB::AMOUNTS.keys)[1] } + + it { should have_stack(defined_card, DB::AMOUNTS[defined_card]) } + it { should have_stack(default_card, DB::DEFAULT_AMOUNT) } + it { should_not have_stack(unloaded_card) } + end +end diff --git a/spec/game_spec.rb b/spec/game_spec.rb index b6316df..7850939 100644 --- a/spec/game_spec.rb +++ b/spec/game_spec.rb @@ -1,29 +1,4 @@ require 'spec_helper' describe Dominion::Game do - describe 'the initial board' do - before do - subject.load_cards(:copper, :silver, :gold, :provence) - end - - it 'contains 60 copper' do - subject.board.detect {|x| x[0][:key] == :copper }.length.should == 60 - end - - it 'contains 40 silver' do - subject.board.detect {|x| x[0][:key] == :silver }.length.should == 40 - end - - it 'contains 30 gold' do - subject.board.detect {|x| x[0][:key] == :gold }.length.should == 30 - end - - it 'contains 8 provences' do - subject.board.detect {|x| x[0][:key] == :provence }.length.should == 8 - end - - it 'contains none of a card if it has not been loaded' do - subject.board.detect {|x| x[0][:key] == :duchy }.should be_nil - end - end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b5f6a4f..c8f5153 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,133 +1,156 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| game.engine.prompt # TODO: Check auto complete begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] game.engine.prompt[:autocomplete]['co'].should == 'Copper' game.engine.prompt[:autocomplete]['es'].should == nil game.engine.prompt[:autocomplete]['ce'].should == nil ensure game.player = old_player end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.engine.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end +Spec::Matchers.define :have_stack do |card, number| + match do |board| + stack = board.detect {|x| x[0][:key] == card } + if number + stack && stack.length == number + else + stack + end + end + + failure_message_for_should do |board| + "expected board #{format_board(board)} to have #{number} x #{card}" + end + + failure_message_for_should_not do |board| + "expected board #{format_board(board)} to not have #{card}" + end + + def format_board(board) + "|%s|" % board.map {|x| "%i x %s" % [x.length, x[0][:name]] }.join(", ") + end +end + module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) end end def game @game end def card(key) @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.engine.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end def played(cards = nil) player[:played] = cards || player[:played] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end
xaviershay/dominion-solitaire
531512d7f15b65afec641bfa128173a401a7b3a2
Refactor board
diff --git a/lib/dominion/board.rb b/lib/dominion/board.rb new file mode 100644 index 0000000..7d7d28d --- /dev/null +++ b/lib/dominion/board.rb @@ -0,0 +1,31 @@ +module Dominion + module Board + DEFAULT_CARDS = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] + DEFAULT_AMOUNT = 8 + AMOUNTS = { + :copper => 60, + :silver => 40, + :gold => 30 + } + + def board + @board ||= begin + (card_set & cards.keys).map {|x| + card_array(x, AMOUNTS[x] || DEFAULT_AMOUNT) + } + end + end + + def card_set + DEFAULT_CARDS + randomize(cards.keys - DEFAULT_CARDS)[0..9] + end + + def card(key) + cards[key] || raise("No card #{key}") + end + + def card_array(key, number) + [card(key)] * number + end + end +end diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index c92e22e..a0e3d69 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,170 +1,148 @@ require 'dominion/ui' require 'dominion/util' require 'dominion/player' +require 'dominion/board' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player + include Dominion::Board - attr_accessor :engine, :board, :cards, :turn + attr_accessor :engine, :cards, :turn def initialize self.cards = {} self.turn = 1 self.engine = Dominion::UI::NCurses.new end - def default_cards - [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] - end - - def board - @board ||= begin - (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| - if @cards.has_key?(x) - [card(x)] * ({ - :copper => 60, - :silver => 40, - :gold => 30 - }[x] || 8) - else - nil - end - }.compact - end - end - - def card(key) - cards[key] || raise("No card #{key}") - end - def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) prompt = engine.prompt if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
12d66176028f788cc4ef11767087ef6a50aa5cd9
Player= to make specs pass
diff --git a/lib/dominion/player.rb b/lib/dominion/player.rb index ada55c4..8425b29 100644 --- a/lib/dominion/player.rb +++ b/lib/dominion/player.rb @@ -1,137 +1,141 @@ module Dominion module Player + def player=(value) + @player = value + end + def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :trashed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] player[:discarded] = [] player[:trashed] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end end
xaviershay/dominion-solitaire
75932aa16f687719cdb1ceba3937c381b68e3232
Spec for default board
diff --git a/spec/game_spec.rb b/spec/game_spec.rb new file mode 100644 index 0000000..b6316df --- /dev/null +++ b/spec/game_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe Dominion::Game do + describe 'the initial board' do + before do + subject.load_cards(:copper, :silver, :gold, :provence) + end + + it 'contains 60 copper' do + subject.board.detect {|x| x[0][:key] == :copper }.length.should == 60 + end + + it 'contains 40 silver' do + subject.board.detect {|x| x[0][:key] == :silver }.length.should == 40 + end + + it 'contains 30 gold' do + subject.board.detect {|x| x[0][:key] == :gold }.length.should == 30 + end + + it 'contains 8 provences' do + subject.board.detect {|x| x[0][:key] == :provence }.length.should == 8 + end + + it 'contains none of a card if it has not been loaded' do + subject.board.detect {|x| x[0][:key] == :duchy }.should be_nil + end + end +end
xaviershay/dominion-solitaire
b6a9cfaeb9b15decc95eedd92c26ec1c4c96d4e0
Refactor player code
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 0e9510c..c92e22e 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,205 +1,170 @@ require 'dominion/ui' require 'dominion/util' require 'dominion/player' require 'dominion/input' module Dominion class Game include Dominion::Util include Dominion::Player - attr_accessor :board, :cards, :player, :turn + attr_accessor :engine, :board, :cards, :turn def initialize - @cards = {} - @turn = 1 - + self.cards = {} + self.turn = 1 self.engine = Dominion::UI::NCurses.new end - def player - @player ||= { - :actions => 1, - :buys => 1, - :gold => 0, - :hand => [], - :discard => [], - :trash => [], - :played => [], - :revealed => [], - :bought => [], - :discarded => [], - :trashed => [], - :deck => randomize( - [cards[:estate]] * 3 + - [cards[:copper]] * 7 - ).compact - } - end - def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end -# [card(:copper)] * 60, -# [card(:silver)] * 40, -# [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end - def test - print_board(board) - - require 'pp' - 5.times { draw_card(player) } - print_player(player) - play_card(player, :cellar) - pp player - end - - attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) prompt = engine.prompt if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/player.rb b/lib/dominion/player.rb index cb8ebb5..ada55c4 100644 --- a/lib/dominion/player.rb +++ b/lib/dominion/player.rb @@ -1,117 +1,137 @@ module Dominion module Player + def player + @player ||= { + :actions => 1, + :buys => 1, + :gold => 0, + :hand => [], + :discard => [], + :trash => [], + :played => [], + :revealed => [], + :bought => [], + :discarded => [], + :trashed => [], + :deck => randomize( + [cards[:estate]] * 3 + + [cards[:copper]] * 7 + ).compact + } + end + def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] player[:discarded] = [] player[:trashed] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end end
xaviershay/dominion-solitaire
74a4d4a858842e9ec8592ea3052aa23567cda566
gitignore
diff --git a/.gitignore b/.gitignore index b14c548..36040c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ debug.log +boards +*.log
xaviershay/dominion-solitaire
36c29254a476e3e57565f4220c3c5130a976e9aa
Refactor game.rb into multiple files
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 69c9558..0e9510c 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,433 +1,205 @@ require 'dominion/ui' +require 'dominion/util' +require 'dominion/player' +require 'dominion/input' module Dominion - module Util - def add_defaults_to_card(name, values) - values = values.dup - values[:key] = name - values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } - - if [*values[:type]].include?(:action) - existing = values[:behaviour] - values[:behaviour] = lambda do |game, card| - game.player[:actions] += card[:actions].to_i - game.player[:buys] += card[:buys].to_i - game.player[:gold] += card[:gold].to_i - card[:cards].to_i.times do - draw_card(game.player) - end - existing[game, card] if existing - end - end - values - end - - def generate_names!(cards) - cards.each do |key, values| - add_defaults_to_card(key, values) - end - end - - def randomize(array) - array.sort_by { rand } - end - - def print_board(board) - board.each do |pile| - puts "$%i: %i x %s" % [ - pile.first[:cost], - pile.length, - pile.first[:name]] - end - end - - def print_player(player) - puts "Hand: %s" % player[:hand].map {|x| - x[:name] - }.join(", ") - end - end - - module Player - def move_card(card, from, to) - key = if card.is_a?(Symbol) - card = from.detect {|x| x[:key] == card } - else - card = from.detect {|x| x[:key] == card[:key] } - end - - from.delete_at(from.index(card)) - to.unshift(card) - card - end - - def draw_card(player) - if player[:deck].length == 0 - player[:deck] = randomize(player[:discard]) - player[:discard] = [] - end - - player[:hand] << player[:deck].shift unless player[:deck].empty? - end - - def reveal_card(player) - if player[:deck].length == 0 - player[:deck] = randomize(player[:discard]) - player[:discard] = [] - end - - unless player[:deck].empty? - player[:deck].shift.tap do |c| - player[:revealed] << c - end - end - end - - def gain_card(board, player, card_name_or_key) - attr = card_name_or_key.is_a?(Symbol) ? :key : :name - pile = board.detect {|pile| pile[0][attr] == card_name_or_key } - pile.shift.tap do |card| - player[:discard] << card - end - end - - def buy_card(board, player, card_name) - pile = board.detect {|pile| pile[0][:name] == card_name.to_s } - pile.shift.tap do |card| - player[:bought] << card.dup - player[:discard] << card - player[:gold] -= card[:cost] - player[:buys] -= 1 - end - end - - def play_card(player, card_name) - card = player[:hand].detect {|x| x[:name] == card_name.to_s } - - player[:hand].delete_at(player[:hand].index(card)) - player[:played] << card - player[:actions] -= 1 - - card[:behaviour][self, card] - end - - def discard_card(player, card_name) - card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } - - player[:hand].delete_at(player[:hand].index(card)) - player[:discarded] << card.dup - player[:discard] << card - end - - def trash_card(player, card_name) - card = player[:hand].detect {|x| x[:name] == card_name.to_s } - - player[:hand].delete_at(player[:hand].index(card)) - player[:trashed] << card - player[:trash] << card - end - - def format_cards(cards) - cards.inject({}) {|a, card| - a[card[:name]] ||= 0 - a[card[:name]] += 1 - a - }.map {|name, kount| - if kount == 1 - name - else - "#{name} x #{kount}" - end - }.sort.join(", ") - end - - def cleanup(board, player) - buffer = ["Turn #{@turn}"] - buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? - buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? - buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? - buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? - buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? - log buffer.join("\n") + "\n\n" - - player[:discard] += player[:hand] - player[:discard] += player[:played] - player[:hand] = [] - player[:played] = [] - player[:discarded] = [] - player[:trashed] = [] - player[:bought] = [] - 5.times { draw_card(player) } - player[:actions] = 1 - player[:buys] = 1 - player[:gold] = 0 - end - end - - class Input - def self.accept_cards(opts) - lambda {|game, card| - inputs = [] - - game.engine.prompt = { - :prompt => opts[:prompt].call(game, inputs), - :autocomplete => opts[:strategy].call(game), - :accept => lambda {|input| - if input - inputs << input - existing = game.engine.prompt - game.engine.prompt = nil - opts[:each].call(game, input) if opts[:each] - - - unless game.engine.prompt || (opts[:max] && inputs.length >= opts[:max]) - game.engine.prompt = existing - game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) - end - else - if !opts[:min] || inputs.length >= opts[:min] - game.engine.prompt = nil - end - end - - if opts[:after] && game.engine.prompt.nil? - opts[:after].call(game, inputs) - end - } - } - } - end - - class Autocomplete - def self.cards_on_board(match_func = lambda {|x| true }) - lambda {|game| - lambda {|input| - suggest = input.length == 0 ? nil : game.board.detect {|x| - x[0][:name] =~ /^#{input}/i && match_func[x[0]] - } - suggest ? suggest[0][:name] : nil - } - } - end - - def self.cards_in_hand(match_func = lambda {|x| true }) - lambda {|game| - lambda {|input| - suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| - x[:name] =~ /^#{input}/i && match_func[x] - } - suggest ? suggest[:name] : nil - } - } - end - - def self.boolean - lambda {|game| - lambda {|input| - %w(Y N).detect {|x| x == input.upcase } || nil - } - } - end - end - end - - class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :trashed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] unless player[:hand].detect {|x| x[:key] == :throne_room } while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def wrap_behaviour(&block) prompt = engine.prompt if prompt # Add an after function to the prompt, rather than running the code now existing = prompt[:accept] prompt[:accept] = lambda {|input| existing[input] wrap_behaviour { block.call } } else block.call end end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/input.rb b/lib/dominion/input.rb new file mode 100644 index 0000000..7f1efe3 --- /dev/null +++ b/lib/dominion/input.rb @@ -0,0 +1,68 @@ +module Dominion + class Input + def self.accept_cards(opts) + lambda {|game, card| + inputs = [] + + game.engine.prompt = { + :prompt => opts[:prompt].call(game, inputs), + :autocomplete => opts[:strategy].call(game), + :accept => lambda {|input| + if input + inputs << input + existing = game.engine.prompt + game.engine.prompt = nil + opts[:each].call(game, input) if opts[:each] + + + unless game.engine.prompt || (opts[:max] && inputs.length >= opts[:max]) + game.engine.prompt = existing + game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) + end + else + if !opts[:min] || inputs.length >= opts[:min] + game.engine.prompt = nil + end + end + + if opts[:after] && game.engine.prompt.nil? + opts[:after].call(game, inputs) + end + } + } + } + end + + class Autocomplete + def self.cards_on_board(match_func = lambda {|x| true }) + lambda {|game| + lambda {|input| + suggest = input.length == 0 ? nil : game.board.detect {|x| + x[0][:name] =~ /^#{input}/i && match_func[x[0]] + } + suggest ? suggest[0][:name] : nil + } + } + end + + def self.cards_in_hand(match_func = lambda {|x| true }) + lambda {|game| + lambda {|input| + suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| + x[:name] =~ /^#{input}/i && match_func[x] + } + suggest ? suggest[:name] : nil + } + } + end + + def self.boolean + lambda {|game| + lambda {|input| + %w(Y N).detect {|x| x == input.upcase } || nil + } + } + end + end + end +end diff --git a/lib/dominion/player.rb b/lib/dominion/player.rb new file mode 100644 index 0000000..cb8ebb5 --- /dev/null +++ b/lib/dominion/player.rb @@ -0,0 +1,117 @@ +module Dominion + module Player + def move_card(card, from, to) + key = if card.is_a?(Symbol) + card = from.detect {|x| x[:key] == card } + else + card = from.detect {|x| x[:key] == card[:key] } + end + + from.delete_at(from.index(card)) + to.unshift(card) + card + end + + def draw_card(player) + if player[:deck].length == 0 + player[:deck] = randomize(player[:discard]) + player[:discard] = [] + end + + player[:hand] << player[:deck].shift unless player[:deck].empty? + end + + def reveal_card(player) + if player[:deck].length == 0 + player[:deck] = randomize(player[:discard]) + player[:discard] = [] + end + + unless player[:deck].empty? + player[:deck].shift.tap do |c| + player[:revealed] << c + end + end + end + + def gain_card(board, player, card_name_or_key) + attr = card_name_or_key.is_a?(Symbol) ? :key : :name + pile = board.detect {|pile| pile[0][attr] == card_name_or_key } + pile.shift.tap do |card| + player[:discard] << card + end + end + + def buy_card(board, player, card_name) + pile = board.detect {|pile| pile[0][:name] == card_name.to_s } + pile.shift.tap do |card| + player[:bought] << card.dup + player[:discard] << card + player[:gold] -= card[:cost] + player[:buys] -= 1 + end + end + + def play_card(player, card_name) + card = player[:hand].detect {|x| x[:name] == card_name.to_s } + + player[:hand].delete_at(player[:hand].index(card)) + player[:played] << card + player[:actions] -= 1 + + card[:behaviour][self, card] + end + + def discard_card(player, card_name) + card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } + + player[:hand].delete_at(player[:hand].index(card)) + player[:discarded] << card.dup + player[:discard] << card + end + + def trash_card(player, card_name) + card = player[:hand].detect {|x| x[:name] == card_name.to_s } + + player[:hand].delete_at(player[:hand].index(card)) + player[:trashed] << card + player[:trash] << card + end + + def format_cards(cards) + cards.inject({}) {|a, card| + a[card[:name]] ||= 0 + a[card[:name]] += 1 + a + }.map {|name, kount| + if kount == 1 + name + else + "#{name} x #{kount}" + end + }.sort.join(", ") + end + + def cleanup(board, player) + buffer = ["Turn #{@turn}"] + buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? + buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? + buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? + buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? + buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? + log buffer.join("\n") + "\n\n" + + player[:discard] += player[:hand] + player[:discard] += player[:played] + player[:hand] = [] + player[:played] = [] + player[:discarded] = [] + player[:trashed] = [] + player[:bought] = [] + 5.times { draw_card(player) } + player[:actions] = 1 + player[:buys] = 1 + player[:gold] = 0 + end + end +end diff --git a/lib/dominion/util.rb b/lib/dominion/util.rb new file mode 100644 index 0000000..2188e78 --- /dev/null +++ b/lib/dominion/util.rb @@ -0,0 +1,48 @@ +module Dominion + module Util + def add_defaults_to_card(name, values) + values = values.dup + values[:key] = name + values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } + + if [*values[:type]].include?(:action) + existing = values[:behaviour] + values[:behaviour] = lambda do |game, card| + game.player[:actions] += card[:actions].to_i + game.player[:buys] += card[:buys].to_i + game.player[:gold] += card[:gold].to_i + card[:cards].to_i.times do + draw_card(game.player) + end + existing[game, card] if existing + end + end + values + end + + def generate_names!(cards) + cards.each do |key, values| + add_defaults_to_card(key, values) + end + end + + def randomize(array) + array.sort_by { rand } + end + + def print_board(board) + board.each do |pile| + puts "$%i: %i x %s" % [ + pile.first[:cost], + pile.length, + pile.first[:name]] + end + end + + def print_player(player) + puts "Hand: %s" % player[:hand].map {|x| + x[:name] + }.join(", ") + end + end +end
xaviershay/dominion-solitaire
98089a4afe958635c2f18f8b8aa5544030db0e8e
Fix Throne Room + cards that need input (mine)
diff --git a/lib/dominion/cards/throne_room.rb b/lib/dominion/cards/throne_room.rb index 97d67d1..4841632 100644 --- a/lib/dominion/cards/throne_room.rb +++ b/lib/dominion/cards/throne_room.rb @@ -1,21 +1,23 @@ Dominion::CARDS[:throne_room] = { :type => :action, :cost => 4, :description => 'Choose an action in your hand, play it twice', :behaviour => Dominion::Input.accept_cards( :strategy => Dominion::Input::Autocomplete.cards_in_hand(lambda {|card| [*card[:type]].include?(:action) }), :prompt => lambda {|game, inputs| "action?" % (4 - inputs.length) }, :each => lambda {|game, input| card = game.player[:hand].detect {|x| x[:name] == input } if card card[:behaviour][game, card] - card[:behaviour][game, card] + game.wrap_behaviour do + card[:behaviour][game, card] + end game.move_card(card, game.player[:hand], game.player[:played]) end }, :min => 1, :max => 1 ) } diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 1570aea..69c9558 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,413 +1,433 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] player[:discarded] = [] player[:trashed] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input + existing = game.engine.prompt + game.engine.prompt = nil opts[:each].call(game, input) if opts[:each] - game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) - if opts[:max] && inputs.length >= opts[:max] - game.engine.prompt = nil + unless game.engine.prompt || (opts[:max] && inputs.length >= opts[:max]) + game.engine.prompt = existing + game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :trashed => [], :deck => randomize( - [cards[:estate]] * 3 + - [cards[:copper]] * 7 + [cards[:estate]] * 3 + + [cards[:copper]] * 7 ).compact } end def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] - while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } - play_card(player, to_play[:name]) - skip = true + unless player[:hand].detect {|x| x[:key] == :throne_room } + while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } + play_card(player, to_play[:name]) + skip = true + end end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end + def wrap_behaviour(&block) + prompt = engine.prompt + + if prompt + # Add an after function to the prompt, rather than running the code now + existing = prompt[:accept] + prompt[:accept] = lambda {|input| + existing[input] + + wrap_behaviour { block.call } + } + else + block.call + end + end + def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/spec/cards/throne_room_spec.rb b/spec/cards/throne_room_spec.rb index 69df5e3..eed2c6e 100644 --- a/spec/cards/throne_room_spec.rb +++ b/spec/cards/throne_room_spec.rb @@ -1,31 +1,43 @@ require 'spec_helper' -describe_card :throne_room, :needs_cards => [:woodcutter] do +describe_card :throne_room, :needs_cards => [:woodcutter, :moneylender] do it_should_behave_like 'an action card' describe 'when played' do it 'allows me to play an action card in my hand twice' do hand cards(:woodcutter, 1) playing_card do input 'Woodcutter' end player[:buys].should == 3 player[:gold].should == 4 hand.should have_cards([]) played.should have_cards(cards(:throne_room, 1) + cards(:woodcutter, 1)) end it 'does nothing when no action cards in hand' do playing_card end it 'forces me to choose an action' do hand cards(:woodcutter, 1) playing_card game.should have_prompt end + + it 'allows me to play an action card in my hand that requires input twice' do + hand cards(:moneylender, 1) + cards(:copper, 2) + + playing_card do + input 'Moneylender' + input 'y' + input 'y' + end + + trash.should have_cards(cards(:copper, 2)) + end end end
xaviershay/dominion-solitaire
2d1dd1e7b88a6b176663d739c62094dcd8991c2a
Extra space in log
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 6f2d4b6..1570aea 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,413 +1,413 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? - log buffer.join("\n") + "\n" + log buffer.join("\n") + "\n\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] player[:discarded] = [] player[:trashed] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :trashed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
12cd0b0d24901a36985e0d334446a89a9841d338
Log trashed cards
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 4b95f17..6f2d4b6 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,409 +1,413 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) + player[:trashed] << card player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? + buffer << "Trashed: #{format_cards(player[:trashed])}" unless player[:trashed].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] player[:discarded] = [] + player[:trashed] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], + :trashed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
040fc25ab2a30e067a3dd63e0f400873977fe740
Correct cost for Smithy
diff --git a/lib/dominion/cards/smithy.rb b/lib/dominion/cards/smithy.rb index 14cc827..7fb73f3 100644 --- a/lib/dominion/cards/smithy.rb +++ b/lib/dominion/cards/smithy.rb @@ -1,5 +1,5 @@ Dominion::CARDS[:smithy] = { - :cost => 5, + :cost => 4, :type => :action, :cards => 3 }
xaviershay/dominion-solitaire
8f83927a463ad369b1712922e9857ec0e8f70588
Better input handling
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 37da3b1..4b95f17 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,409 +1,409 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def format_cards(cards) cards.inject({}) {|a, card| a[card[:name]] ||= 0 a[card[:name]] += 1 a }.map {|name, kount| if kount == 1 name else "#{name} x #{kount}" end }.sort.join(", ") end def cleanup(board, player) buffer = ["Turn #{@turn}"] buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? log buffer.join("\n") + "\n" player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] player[:discarded] = [] player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :bought => [], :discarded => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| - x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i + x[:cost] <= treasure(player) && x[:name] =~ /^#{Regexp.escape(input)}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 7f1dcfc..746e9a0 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,297 +1,300 @@ require 'ffi-ncurses' module Dominion; module UI; end; end; class Dominion::UI::NCurses include FFI::NCurses attr_accessor :prompt, :input_buffer, :card_active def setup self.prompt = nil self.input_buffer = '' initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(ctx) ch = wgetch(ctx[:input_window]) if prompt case ch when 10 - prompt[:accept][prompt[:autocomplete][input_buffer]] + autocompleted = prompt[:autocomplete][input_buffer] + if !(autocompleted == nil && input_buffer.length > 0) + prompt[:accept][autocompleted] + end self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else - self.input_buffer += ch.chr + self.input_buffer += ch.chr if ch.chr =~ /^[a-z ]+$/i end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = prompt[:autocomplete][input_buffer].to_s print_with_color[prompt[:color] || :yellow_back, "%s %s" % [ prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end def card_active?(card) (self.card_active || lambda { false }).call(card) end end
xaviershay/dominion-solitaire
e6cc639f466137737a3bf7e2b3379b28f89e9509
Better descriptions
diff --git a/lib/dominion/cards/library.rb b/lib/dominion/cards/library.rb index ee7d59d..33832eb 100644 --- a/lib/dominion/cards/library.rb +++ b/lib/dominion/cards/library.rb @@ -1,35 +1,35 @@ Dominion::CARDS[:library] = { :type => :action, :cost => 5, - :description => 'Draw to 7 cards, discarding action cards as they are drawn', + :description => 'Draw to 7 cards, discard actions as they are drawn', :behaviour => lambda {|game, card| player = game.player revealed = [] non_action = lambda { revealed.reject {|x| [*x[:type]].include?(:action) } } while (player[:hand] + non_action[]).length < 7 && !(player[:deck] + player[:discard]).empty? game.reveal_card(player).tap do |c| revealed << c if c end end game.engine.prompt = { :prompt => "Press enter to continue", :autocomplete => lambda {|input| nil }, :accept => lambda {|input| game.engine.prompt = nil non_action[].each do |t| game.move_card(t, player[:revealed], player[:hand]) revealed.delete_at(revealed.index(t)) end revealed.each do |c| game.move_card(c, player[:revealed], player[:discard]) end } } } } diff --git a/lib/dominion/cards/militia.rb b/lib/dominion/cards/militia.rb index 329ceff..222db00 100644 --- a/lib/dominion/cards/militia.rb +++ b/lib/dominion/cards/militia.rb @@ -1,6 +1,6 @@ Dominion::CARDS[:militia] = { :type => [:attack, :action], :cost => 4, - :description => 'Other players discard down to 3 cards', + :description => 'Others discard down to 3 cards', :gold => 2 } diff --git a/lib/dominion/cards/moneylender.rb b/lib/dominion/cards/moneylender.rb index 4f8ef5e..51a695a 100644 --- a/lib/dominion/cards/moneylender.rb +++ b/lib/dominion/cards/moneylender.rb @@ -1,21 +1,21 @@ Dominion::CARDS[:moneylender] = { :type => :action, :cost => 4, :description => 'Trash a copper, +3T', :behaviour => lambda {|game, card| if game.player[:hand].detect {|x| x[:key] == :copper } game.engine.prompt = { - :prompt => "Trash a copper (n/Y)?", + :prompt => "Trash a copper (N/y)?", :autocomplete => Dominion::Input::Autocomplete.boolean[game], :accept => lambda {|input| if input == 'Y' game.move_card(:copper, game.player[:hand], game.player[:trash]) game.player[:gold] += 3 end game.engine.prompt = nil } } end } } diff --git a/lib/dominion/cards/thief.rb b/lib/dominion/cards/thief.rb new file mode 100644 index 0000000..03c868a --- /dev/null +++ b/lib/dominion/cards/thief.rb @@ -0,0 +1,5 @@ +Dominion::CARDS[:thief] = { + :cost => 4, + :type => [:attack, :action], + :description => 'Others discard 2 from deck, you trash or gain <= 1T' +}
xaviershay/dominion-solitaire
46f45e899ade2e2bd653a2c2060fd6661c8d16ec
Library
diff --git a/lib/dominion/cards/library.rb b/lib/dominion/cards/library.rb new file mode 100644 index 0000000..ee7d59d --- /dev/null +++ b/lib/dominion/cards/library.rb @@ -0,0 +1,35 @@ +Dominion::CARDS[:library] = { + :type => :action, + :cost => 5, + :description => 'Draw to 7 cards, discarding action cards as they are drawn', + :behaviour => lambda {|game, card| + player = game.player + revealed = [] + + non_action = lambda { + revealed.reject {|x| [*x[:type]].include?(:action) } + } + while (player[:hand] + non_action[]).length < 7 && !(player[:deck] + player[:discard]).empty? + game.reveal_card(player).tap do |c| + revealed << c if c + end + end + + game.engine.prompt = { + :prompt => "Press enter to continue", + :autocomplete => lambda {|input| nil }, + :accept => lambda {|input| + game.engine.prompt = nil + + non_action[].each do |t| + game.move_card(t, player[:revealed], player[:hand]) + revealed.delete_at(revealed.index(t)) + end + + revealed.each do |c| + game.move_card(c, player[:revealed], player[:discard]) + end + } + } + } +} diff --git a/spec/cards/library_spec.rb b/spec/cards/library_spec.rb new file mode 100644 index 0000000..031efa6 --- /dev/null +++ b/spec/cards/library_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe_card :library do + it_should_behave_like 'an action card' + + describe 'when played' do + it 'reveals cards until hand + revealed non-action cards = 7, then discards actions, and puts non-action into hand' do + deck cards(:library, 3) + cards(:estate, 10) + hand cards(:estate, 3) + cards(:library, 3) + + playing_card + + hand.should have_cards(cards(:estate, 4) + cards(:library, 3)) + discard.should have_cards(cards(:library, 3)) + end + end +end
xaviershay/dominion-solitaire
9de937c376880568708747548bec014732ae8c72
Game logging
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 622eff0..37da3b1 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,382 +1,409 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name - values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } + values[:name] = name.to_s.tr('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| + player[:bought] << card.dup player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) + player[:discarded] << card.dup player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end + def format_cards(cards) + cards.inject({}) {|a, card| + a[card[:name]] ||= 0 + a[card[:name]] += 1 + a + }.map {|name, kount| + if kount == 1 + name + else + "#{name} x #{kount}" + end + }.sort.join(", ") + end + def cleanup(board, player) + buffer = ["Turn #{@turn}"] + buffer << "Hand: #{format_cards(player[:hand])}" unless player[:hand].empty? + buffer << "Played: #{format_cards(player[:played])}" unless player[:played].empty? + buffer << "Discarded: #{format_cards(player[:discarded])}" unless player[:discarded].empty? + buffer << "Bought: #{format_cards(player[:bought])}" unless player[:bought].empty? + log buffer.join("\n") + "\n" + player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] + player[:discarded] = [] + player[:bought] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], + :bought => [], + :discarded => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def default_cards [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] end def board @board ||= begin (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
a2773a3ade975142b4aab75fbcf143abe4a92f9e
Quick hack to load a specific board
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index eb15aec..622eff0 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,379 +1,382 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end + def default_cards + [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] + end + def board @board ||= begin - defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] - (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| + (default_cards + randomize(@cards.keys - default_cards)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/run.rb b/lib/run.rb index f723e0d..01e878a 100644 --- a/lib/run.rb +++ b/lib/run.rb @@ -1,13 +1,20 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) def log(message) @log ||= File.open('debug.log', 'a') @log.puts message @log.flush end require 'dominion/game' game = Dominion::Game.new -game.load_all_cards + +if ARGV[0] + board = File.open(ARGV[0]).read.lines.reject {|x| x[0] == '#'[0] }.map {|x| x.chomp.downcase.tr(' ', '_').to_sym } + board += game.default_cards + game.load_cards(*board) +else + game.load_all_cards +end game.run
xaviershay/dominion-solitaire
bee0e205b8fa36da4a2ff3fd2fe007388d6c49ca
Council Room + Gardens
diff --git a/lib/dominion/cards/council_room.rb b/lib/dominion/cards/council_room.rb new file mode 100644 index 0000000..8d22299 --- /dev/null +++ b/lib/dominion/cards/council_room.rb @@ -0,0 +1,7 @@ +Dominion::CARDS[:council_room] = { + :cost => 5, + :type => :action, + :description => 'Each other player draws a card', + :cards => 4, + :buys => 1 +} diff --git a/lib/dominion/cards/gardens.rb b/lib/dominion/cards/gardens.rb new file mode 100644 index 0000000..75c6c8e --- /dev/null +++ b/lib/dominion/cards/gardens.rb @@ -0,0 +1,5 @@ +Dominion::CARDS[:gardens] = { + :cost => 4, + :type => :victory, + :description => '1VP per 10 cards in your deck, rounded down' +} diff --git a/spec/cards/council_room_spec.rb b/spec/cards/council_room_spec.rb new file mode 100644 index 0000000..b578d91 --- /dev/null +++ b/spec/cards/council_room_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe_card :council_room do + it_should_behave_like 'an action card' + + it 'each other player should draw a card' do + # Unimplemented - not for solitaire + end +end diff --git a/spec/cards/victory_spec.rb b/spec/cards/victory_spec.rb index ae48bad..4e9de38 100644 --- a/spec/cards/victory_spec.rb +++ b/spec/cards/victory_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -[:estate, :duchy, :provence, :curse].each do |name| +[:gardens, :estate, :duchy, :provence, :curse].each do |name| describe_card name do it_should_behave_like 'a victory card' end end
xaviershay/dominion-solitaire
eddcfe6fe52e764893ad27e1365b213d0608f673
Fix spy specs
diff --git a/spec/cards/spy_spec.rb b/spec/cards/spy_spec.rb index 58b0f92..8edbca6 100644 --- a/spec/cards/spy_spec.rb +++ b/spec/cards/spy_spec.rb @@ -1,36 +1,38 @@ require 'spec_helper' describe_card :spy do it_should_behave_like 'an action card' it_should_behave_like 'an attack card' describe 'when played' do it 'reveals top card and allows to discard' do - deck cards(:estate, 1) + deck cards(:copper, 1) + cards(:estate, 1) playing_card do input 'Y' end + hand.should have_cards(cards(:copper, 1)) deck.should have_cards([]) discard.should have_cards(cards(:estate, 1)) end it 'reveals top card and allows to put back' do - deck cards(:estate, 1) + deck cards(:copper, 1) + cards(:estate, 1) playing_card do input 'N' end + hand.should have_cards(cards(:copper, 1)) discard.should have_cards([]) deck.should have_cards(cards(:estate, 1)) end it 'should do nothing if no cards in deck/discard' do deck [] playing_card end end end
xaviershay/dominion-solitaire
995e64a4e6b70e7387600b55a67f2fc210bb8389
Throne room
diff --git a/lib/dominion/cards/throne_room.rb b/lib/dominion/cards/throne_room.rb new file mode 100644 index 0000000..97d67d1 --- /dev/null +++ b/lib/dominion/cards/throne_room.rb @@ -0,0 +1,21 @@ +Dominion::CARDS[:throne_room] = { + :type => :action, + :cost => 4, + :description => 'Choose an action in your hand, play it twice', + :behaviour => Dominion::Input.accept_cards( + :strategy => Dominion::Input::Autocomplete.cards_in_hand(lambda {|card| [*card[:type]].include?(:action) }), + :prompt => lambda {|game, inputs| "action?" % (4 - inputs.length) }, + :each => lambda {|game, input| + card = game.player[:hand].detect {|x| x[:name] == input } + + if card + card[:behaviour][game, card] + card[:behaviour][game, card] + + game.move_card(card, game.player[:hand], game.player[:played]) + end + }, + :min => 1, + :max => 1 + ) +} diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 2777067..eb15aec 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,379 +1,379 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) key = if card.is_a?(Symbol) card = from.detect {|x| x[:key] == card } else card = from.detect {|x| x[:key] == card[:key] } end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end - def self.cards_in_hand + def self.cards_in_hand(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| - x[:name] =~ /^#{input}/i + x[:name] =~ /^#{input}/i && match_func[x] } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def board @board ||= begin defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/spec/cards/throne_room_spec.rb b/spec/cards/throne_room_spec.rb new file mode 100644 index 0000000..69df5e3 --- /dev/null +++ b/spec/cards/throne_room_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +describe_card :throne_room, :needs_cards => [:woodcutter] do + it_should_behave_like 'an action card' + + describe 'when played' do + it 'allows me to play an action card in my hand twice' do + hand cards(:woodcutter, 1) + + playing_card do + input 'Woodcutter' + end + + player[:buys].should == 3 + player[:gold].should == 4 + + hand.should have_cards([]) + played.should have_cards(cards(:throne_room, 1) + cards(:woodcutter, 1)) + end + + it 'does nothing when no action cards in hand' do + playing_card + end + + it 'forces me to choose an action' do + hand cards(:woodcutter, 1) + playing_card + game.should have_prompt + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 42b24be..b5f6a4f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,129 +1,133 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| game.engine.prompt # TODO: Check auto complete begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] game.engine.prompt[:autocomplete]['co'].should == 'Copper' game.engine.prompt[:autocomplete]['es'].should == nil game.engine.prompt[:autocomplete]['ce'].should == nil ensure game.player = old_player end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.engine.prompt end failure_message_for_should do |game| "expected a prompt" end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) end end def game @game end def card(key) @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.engine.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end + + def played(cards = nil) + player[:played] = cards || player[:played] + end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end
xaviershay/dominion-solitaire
beb6c19fa8ecc7193bdaae6211168a9443b50469
Remodel
diff --git a/lib/dominion/cards/remodel.rb b/lib/dominion/cards/remodel.rb new file mode 100644 index 0000000..43e6857 --- /dev/null +++ b/lib/dominion/cards/remodel.rb @@ -0,0 +1,29 @@ +Dominion::CARDS[:remodel] = { + :type => :action, + :cost => 4, + :description => 'Trash a card, gain a card cost up to +2T more', + :behaviour => lambda {|game, card| + Dominion::Input.accept_cards( + :strategy => Dominion::Input::Autocomplete.cards_in_hand, + :prompt => lambda {|game, card| "trash card?" }, + :min => 1, + :max => 1, + :after => lambda {|game, inputs| + unless inputs.empty? + trashed_card = game.player[:hand].detect {|x| x[:name] == inputs.first } + game.move_card(trashed_card, game.player[:hand], game.player[:trash]) + + Dominion::Input.accept_cards( + :strategy => Dominion::Input::Autocomplete.cards_on_board(lambda {|card| card[:cost] <= trashed_card[:cost] + 2 }), + :prompt => lambda {|game, card| "gain card <= #{trashed_card[:cost] + 2}T?" }, + :min => 1, + :max => 1, + :each => lambda {|game, input| + game.gain_card(game.board, game.player, input) + } + )[game, card] + end + } + )[game, card] + } +} diff --git a/spec/cards/remodel_spec.rb b/spec/cards/remodel_spec.rb new file mode 100644 index 0000000..e5fd29a --- /dev/null +++ b/spec/cards/remodel_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe_card :remodel, :needs_cards => [:silver, :gold] do + it_should_behave_like 'an action card' + + describe 'when playing' do + it 'allows me to trash an estate for a silver' do + hand cards(:estate, 1) + + playing_card do + input 'estate' + input 'silver' + end + + hand.should have_cards([]) + trash.should have_cards(cards(:estate, 1)) + discard.should have_cards(cards(:silver, 1)) + end + + it 'does not allow me to trash a silver for a gold' do + hand cards(:silver, 1) + + playing_card do + input 'silver' + input 'gold' + end + + game.should have_prompt + hand.should have_cards([]) + trash.should have_cards(cards(:silver, 1)) + discard.should have_cards([]) + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d9f91f..42b24be 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,125 +1,129 @@ require 'spec' $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) require 'dominion/game' require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') class Proc def inspect "[PROC]" end end Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| match do |game| game.engine.prompt # TODO: Check auto complete begin old_player = game.player.dup game.player[:deck] = [game.card(:estate)] game.player[:hand] = [game.card(:copper)] game.engine.prompt[:autocomplete]['co'].should == 'Copper' game.engine.prompt[:autocomplete]['es'].should == nil game.engine.prompt[:autocomplete]['ce'].should == nil ensure game.player = old_player end end failure_message_for_should do |game| "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" end end Spec::Matchers.define :have_prompt do match do |game| game.engine.prompt end + + failure_message_for_should do |game| + "expected a prompt" + end end Spec::Matchers.define :have_cards do |cards| match do |pile| keys(pile) == keys(cards) end failure_message_for_should do |pile| "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" end def keys(pile) pile.map {|x| x[:key] }.sort_by(&:to_s) end end module CardMacros def game_with_cards(*cards) @game = Dominion::Game.new.tap do |game| game.load_cards(*cards + [:copper, :estate]) end end def game @game end def card(key) @game.card(key) end def cards(key, n) [card(key)] * n end def input(key) prompt = @game.engine.prompt prompt[:accept][prompt[:autocomplete][key]] if prompt end def playing_card(card = nil) card ||= subject player[:played] << card card[:behaviour][@game, subject] yield if block_given? input '' end def player @game.player end def deck(cards = nil) player[:deck] = cards || player[:deck] end def hand(cards = nil) player[:hand] = cards || player[:hand] end def trash(cards = nil) player[:trash] = cards || player[:trash] end def discard(cards = nil) player[:discard] = cards || player[:discard] end end Spec::Runner.configure do |config| config.include CardMacros end def describe_card(key, opts = {}, &block) describe(key.to_s) do subject { card(key) } before do game_with_cards(*[key] + (opts[:needs_cards] || [])) end instance_eval(&block) end end
xaviershay/dominion-solitaire
6c5633a0c2a3f2654f559de425ee76b34e23d7f4
Moneylender
diff --git a/lib/dominion/cards/moneylender.rb b/lib/dominion/cards/moneylender.rb new file mode 100644 index 0000000..4f8ef5e --- /dev/null +++ b/lib/dominion/cards/moneylender.rb @@ -0,0 +1,21 @@ +Dominion::CARDS[:moneylender] = { + :type => :action, + :cost => 4, + :description => 'Trash a copper, +3T', + :behaviour => lambda {|game, card| + if game.player[:hand].detect {|x| x[:key] == :copper } + game.engine.prompt = { + :prompt => "Trash a copper (n/Y)?", + :autocomplete => Dominion::Input::Autocomplete.boolean[game], + :accept => lambda {|input| + if input == 'Y' + game.move_card(:copper, game.player[:hand], game.player[:trash]) + game.player[:gold] += 3 + end + + game.engine.prompt = nil + } + } + end + } +} diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index eae5186..2777067 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,375 +1,379 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) - card = from.detect {|x| x[:key] == card[:key] } + key = if card.is_a?(Symbol) + card = from.detect {|x| x[:key] == card } + else + card = from.detect {|x| x[:key] == card[:key] } + end from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_name_or_key) attr = card_name_or_key.is_a?(Symbol) ? :key : :name pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else if !opts[:min] || inputs.length >= opts[:min] game.engine.prompt = nil end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_on_board(match_func = lambda {|x| true }) lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.board.detect {|x| x[0][:name] =~ /^#{input}/i && match_func[x[0]] } suggest ? suggest[0][:name] : nil } } end def self.cards_in_hand lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def board @board ||= begin defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| if @cards.has_key?(x) [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) else nil end }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/spec/cards/moneylender_spec.rb b/spec/cards/moneylender_spec.rb new file mode 100644 index 0000000..045685c --- /dev/null +++ b/spec/cards/moneylender_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe_card :moneylender do + it_should_behave_like 'an action card' + + describe 'when playing' do + it 'allows me to trash a copper to +3 gold' do + hand cards(:copper, 1) + + playing_card do + input 'y' + end + game.should_not have_prompt + + hand.should_not have_cards(cards(:copper, 1)) + trash.should have_cards(cards(:copper, 1)) + end + + it 'does not trash a copper by default' do + hand cards(:copper, 1) + + playing_card + + game.should_not have_prompt + + hand.should have_cards(cards(:copper, 1)) + trash.should_not have_cards(cards(:copper, 1)) + end + + it 'does not prompt if I have no copper in hand' do + playing_card do + game.should_not have_prompt + end + end + end +end
xaviershay/dominion-solitaire
ce06e847ec7b0af66888be5a0eaa8fd817179443
Militia
diff --git a/lib/dominion/cards/militia.rb b/lib/dominion/cards/militia.rb new file mode 100644 index 0000000..329ceff --- /dev/null +++ b/lib/dominion/cards/militia.rb @@ -0,0 +1,6 @@ +Dominion::CARDS[:militia] = { + :type => [:attack, :action], + :cost => 4, + :description => 'Other players discard down to 3 cards', + :gold => 2 +} diff --git a/spec/cards/bureaucrat_spec.rb b/spec/cards/bureaucrat_spec.rb index ee2e261..510278d 100644 --- a/spec/cards/bureaucrat_spec.rb +++ b/spec/cards/bureaucrat_spec.rb @@ -1,23 +1,24 @@ require 'spec_helper' describe_card :bureaucrat, :needs_cards => [:silver] do it_should_behave_like 'an action card' it_should_behave_like 'an attack card' describe 'when played' do it 'puts a silver card on the top of my deck' do deck [] playing_card deck.should have_cards(cards(:silver, 1)) end it 'does not gain a silver if no more are left in the pile' do + pending end it 'forces each other player to reveal a victory card and put it on top of their deck' do # Unimplemented - not relevant for solitaire end end end diff --git a/spec/cards/militia_spec.rb b/spec/cards/militia_spec.rb new file mode 100644 index 0000000..aa496e3 --- /dev/null +++ b/spec/cards/militia_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe_card :militia do + it_should_behave_like 'an action card' + it_should_behave_like 'an attack card' + + describe 'when played' do + it 'forces other players to discard to 3 cards' do + # Unimplemented - not relevant for solitaire + end + end +end
xaviershay/dominion-solitaire
aa4ef4767e86aee0d1fc5b38c97dcd2474a68a15
Workshop
diff --git a/lib/dominion/cards/workshop.rb b/lib/dominion/cards/workshop.rb new file mode 100644 index 0000000..9672c11 --- /dev/null +++ b/lib/dominion/cards/workshop.rb @@ -0,0 +1,14 @@ +Dominion::CARDS[:workshop] = { + :type => :action, + :cost => 3, + :description => 'Gain a card costing <= 4', + :behaviour => Dominion::Input.accept_cards( + :strategy => Dominion::Input::Autocomplete.cards_on_board(lambda {|x| x[:cost] <= 4}), + :prompt => lambda {|game, inputs| "gain card?" }, + :each => lambda {|game, input| + game.gain_card(game.board, game.player, input) + }, + :max => 1, + :min => 1 + ) +} diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 7b3e99b..eae5186 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,357 +1,375 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) card = from.detect {|x| x[:key] == card[:key] } from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end - def gain_card(board, player, card_key) - pile = board.detect {|pile| pile[0][:key] == card_key } + def gain_card(board, player, card_name_or_key) + attr = card_name_or_key.is_a?(Symbol) ? :key : :name + pile = board.detect {|pile| pile[0][attr] == card_name_or_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else - game.engine.prompt = nil + if !opts[:min] || inputs.length >= opts[:min] + game.engine.prompt = nil + end end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete + def self.cards_on_board(match_func = lambda {|x| true }) + lambda {|game| + lambda {|input| + suggest = input.length == 0 ? nil : game.board.detect {|x| + x[0][:name] =~ /^#{input}/i && match_func[x[0]] + } + suggest ? suggest[0][:name] : nil + } + } + end + def self.cards_in_hand lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def board @board ||= begin defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| - [card(x)] * ({ - :copper => 60, - :silver => 40, - :gold => 30 - }[x] || 8) - } + if @cards.has_key?(x) + [card(x)] * ({ + :copper => 60, + :silver => 40, + :gold => 30 + }[x] || 8) + else + nil + end + }.compact end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/spec/cards/workshop_spec.rb b/spec/cards/workshop_spec.rb new file mode 100644 index 0000000..bd06018 --- /dev/null +++ b/spec/cards/workshop_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe_card :workshop, :needs_card => [:gold] do + it_should_behave_like 'an action card' + + describe 'when playing' do + it 'allows me to gain a card costing <= 4' do + playing_card do + input 'gold' # No + input 'estate' # THAT'S HOW I ROLL + end + + discard.should have_cards(cards(:estate, 1)) + end + end +end
xaviershay/dominion-solitaire
2e22910b500cdf9f3ebdde2f08bfc2c08bfc4dfe
Colored prompt for ULTRA QUICK RECOGNITION
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 695d5ea..7b3e99b 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,355 +1,357 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) card = from.detect {|x| x[:key] == card[:key] } from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_key) pile = board.detect {|pile| pile[0][:key] == card_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else game.engine.prompt = nil end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_in_hand lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def board @board ||= begin defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) } end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } autoplay = [:village, :market, :laboratory] while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } play_card(player, to_play[:name]) skip = true end next if skip engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, + :color => :green_back, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { - :prompt => "buy (#{player[:buys]} left)?", + :prompt => "buy (#{treasure(player)}/#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, + :color => :magenta_back, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index 544c41b..7f1dcfc 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,297 +1,297 @@ require 'ffi-ncurses' module Dominion; module UI; end; end; class Dominion::UI::NCurses include FFI::NCurses attr_accessor :prompt, :input_buffer, :card_active def setup self.prompt = nil self.input_buffer = '' initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(ctx) ch = wgetch(ctx[:input_window]) if prompt case ch when 10 prompt[:accept][prompt[:autocomplete][input_buffer]] self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = prompt[:autocomplete][input_buffer].to_s - print_with_color[:yellow_back, "%s %s" % [ + print_with_color[prompt[:color] || :yellow_back, "%s %s" % [ prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end def card_active?(card) (self.card_active || lambda { false }).call(card) end end
xaviershay/dominion-solitaire
7f64e153c2077fd8421d5321e7a0612a15705ddc
Auto play villages, labs and markets
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 2d653ca..695d5ea 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,347 +1,355 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) card = from.detect {|x| x[:key] == card[:key] } from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_key) pile = board.detect {|pile| pile[0][:key] == card_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else game.engine.prompt = nil end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_in_hand lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def board @board ||= begin defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| [card(x)] * ({ :copper => 60, :silver => 40, :gold => 30 }[x] || 8) } end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? - if player[:actions] > 0 - engine.card_active = lambda {|card| card[:type] == :action && player[:hand].include?(card)} + if player[:actions] > 0 && player[:hand].detect {|x| [*x[:type]].include?(:action) } + autoplay = [:village, :market, :laboratory] + while to_play = player[:hand].detect {|x| autoplay.include?(x[:key]) } + play_card(player, to_play[:name]) + skip = true + end + + next if skip + + engine.card_active = lambda {|card| [*card[:type]].include?(:action) && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } - elsif player[:buys] > 0 + elsif player[:buys] > 0 # TODO: option to skip copper buys engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
42be0834b908558fba6f2000a404ef8e4639c3de
UI will be broken for long lines, but won't blow up
diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb index d5dcffb..544c41b 100644 --- a/lib/dominion/ui.rb +++ b/lib/dominion/ui.rb @@ -1,297 +1,297 @@ require 'ffi-ncurses' module Dominion; module UI; end; end; class Dominion::UI::NCurses include FFI::NCurses attr_accessor :prompt, :input_buffer, :card_active def setup self.prompt = nil self.input_buffer = '' initscr start_color noecho # set up colour pairs # Background Foreground init_pair(0, Colour::BLACK, Colour::BLACK) init_pair(1, Colour::RED, Colour::BLACK) init_pair(2, Colour::GREEN, Colour::BLACK) init_pair(3, Colour::YELLOW, Colour::BLACK) init_pair(4, Colour::BLUE, Colour::BLACK) init_pair(5, Colour::MAGENTA, Colour::BLACK) init_pair(6, Colour::CYAN, Colour::BLACK) init_pair(7, Colour::WHITE, Colour::BLACK) init_pair(8, Colour::BLACK, Colour::BLACK) init_pair(9, Colour::BLACK, Colour::RED) init_pair(10, Colour::BLACK, Colour::GREEN) init_pair(11, Colour::BLACK, Colour::YELLOW) init_pair(12, Colour::BLACK, Colour::BLUE) init_pair(13, Colour::BLACK, Colour::MAGENTA) init_pair(14, Colour::BLACK, Colour::CYAN) init_pair(15, Colour::BLACK, Colour::WHITE) end def step(ctx) ch = wgetch(ctx[:input_window]) if prompt case ch when 10 prompt[:accept][prompt[:autocomplete][input_buffer]] self.input_buffer = '' when 127 self.input_buffer = input_buffer[0..-2] else self.input_buffer += ch.chr end end end def finalize endwin end def draw(game, ctx = {}) ctx[:windows] ||= {} curs_set 0 refresh drawn = [{ :coords => [14, 80, 0, 0], :title => 'Board', :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end type_char = [ [:reaction, 'R'], [:attack, 'X'], [:treasure, 'T'], [:victory, 'V'], [:action, 'A'] ] max_name_length = game.board.map {|pile| pile[0][:name].length }.max header, body = game.board.partition {|x| [ :copper, :silver, :gold, :estate, :duchy, :provence, :curse ].include?(x.first[:key]) } header.each_with_index do |pile, i| card = pile.first print_with_color[:white, ' '] if i > 0 print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, pile.size] print_with_color[:white, " %s" % card[:name]] end print_with_color[:white, "\n"] body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| card = pile.first print_with_color[:white, ' '] print_with_color[:yellow, card[:cost]] print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] print_with_color[:blue, '%-2i' % pile.size] if card_active?(card) bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] else print_with_color[:white, " %-#{max_name_length}s " % card[:name]] end print_with_color[:cyan_back, card[:cards] || ' '] print_with_color[:green_back, card[:actions] || ' '] print_with_color[:magenta_back, card[:buys] || ' '] print_with_color[:yellow_back, card[:gold] || ' '] print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] end end }, { :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ game.turn, game.player[:actions], game.player[:buys], game.treasure(game.player), game.player[:discard].length, game.player[:deck].length ], :coords => [10, 80, 14, 0], :draw => lambda do |window, game| bold_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_BOLD, color_index, nil waddstr(window, text.to_s) end print_with_color = lambda do |color, text| color_index = { :white => 0, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end print_with_color[:white, "Hand: "] line_length = 6 game.player[:hand].each_with_index do |card, index| suffix = index == game.player[:hand].length - 1 ? '' : ', ' if card_active?(card) bold_with_color[:white, card[:name] + suffix] else print_with_color[:white, card[:name] + suffix] end line_length += (card[:name] + suffix).length end # TODO: print ' ' doesn't work :( - print_with_color[:white, " " * (77 - line_length)] + print_with_color[:white, " " * (77 - line_length)] if line_length < 76 print_with_color[:white, "\n"] played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") print_with_color[:white, played] - print_with_color[:white, " " * (77 - played.length)] + print_with_color[:white, " " * (77 - played.length)] if played.length < 76 print_with_color[:white, "\n"] unless game.player[:revealed].empty? revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") print_with_color[:white, revealed] print_with_color[:white, " " * (77 - revealed.length)] end end }, { :coords => [1, 80, 24, 0], :border => false, :draw => lambda do |window, game| print_with_color = lambda do |color, text| color_index = { :white => 7, :yellow => 3, :blue => 4, :red => 1, :cyan_back => 14, :green_back => 10, :magenta_back => 13, :yellow_back => 11 }[color] || raise("Unknown color: #{color}") wattr_set window, A_NORMAL, color_index, nil waddstr(window, text.to_s) end if prompt #print_with_color[:yellow_back, "%-80s" % ""] suggest = prompt[:autocomplete][input_buffer].to_s print_with_color[:yellow_back, "%s %s" % [ prompt[:prompt], input_buffer]] fill = suggest[input_buffer.length..-1] if fill && fill.length > 0 print_with_color[:red, "%s" % fill] end else print_with_color[:green_back, "%-80s" % " "] end end }].map do |window| window[:border] = true unless window.has_key?(:border) c = window[:coords] board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) if window[:border] board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) window[:draw][board, game] wattr_set board_frame, A_NORMAL, 7, nil box(board_frame, c[2], c[3]) wmove(board_frame, 0, 2) waddstr(board_frame, "| #{window[:title]} |") wrefresh(board_frame) wrefresh(board) { :frame => board_frame, :inner => board } else window[:draw][board_frame, game] wrefresh(board_frame) { :frame => nil, :inner => board_frame } end end {:input_window => drawn[0][:inner]} end def card_active?(card) (self.card_active || lambda { false }).call(card) end end
xaviershay/dominion-solitaire
32793fe9a44fb3b5f40d784cdfa6690c4db47a01
Random board to start
diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb index 2f00c12..2d653ca 100644 --- a/lib/dominion/game.rb +++ b/lib/dominion/game.rb @@ -1,338 +1,347 @@ require 'dominion/ui' module Dominion module Util def add_defaults_to_card(name, values) values = values.dup values[:key] = name values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } if [*values[:type]].include?(:action) existing = values[:behaviour] values[:behaviour] = lambda do |game, card| game.player[:actions] += card[:actions].to_i game.player[:buys] += card[:buys].to_i game.player[:gold] += card[:gold].to_i card[:cards].to_i.times do draw_card(game.player) end existing[game, card] if existing end end values end def generate_names!(cards) cards.each do |key, values| add_defaults_to_card(key, values) end end def randomize(array) array.sort_by { rand } end def print_board(board) board.each do |pile| puts "$%i: %i x %s" % [ pile.first[:cost], pile.length, pile.first[:name]] end end def print_player(player) puts "Hand: %s" % player[:hand].map {|x| x[:name] }.join(", ") end end module Player def move_card(card, from, to) card = from.detect {|x| x[:key] == card[:key] } from.delete_at(from.index(card)) to.unshift(card) card end def draw_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end player[:hand] << player[:deck].shift unless player[:deck].empty? end def reveal_card(player) if player[:deck].length == 0 player[:deck] = randomize(player[:discard]) player[:discard] = [] end unless player[:deck].empty? player[:deck].shift.tap do |c| player[:revealed] << c end end end def gain_card(board, player, card_key) pile = board.detect {|pile| pile[0][:key] == card_key } pile.shift.tap do |card| player[:discard] << card end end def buy_card(board, player, card_name) pile = board.detect {|pile| pile[0][:name] == card_name.to_s } pile.shift.tap do |card| player[:discard] << card player[:gold] -= card[:cost] player[:buys] -= 1 end end def play_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:played] << card player[:actions] -= 1 card[:behaviour][self, card] end def discard_card(player, card_name) card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } player[:hand].delete_at(player[:hand].index(card)) player[:discard] << card end def trash_card(player, card_name) card = player[:hand].detect {|x| x[:name] == card_name.to_s } player[:hand].delete_at(player[:hand].index(card)) player[:trash] << card end def cleanup(board, player) player[:discard] += player[:hand] player[:discard] += player[:played] player[:hand] = [] player[:played] = [] 5.times { draw_card(player) } player[:actions] = 1 player[:buys] = 1 player[:gold] = 0 end end class Input def self.accept_cards(opts) lambda {|game, card| inputs = [] game.engine.prompt = { :prompt => opts[:prompt].call(game, inputs), :autocomplete => opts[:strategy].call(game), :accept => lambda {|input| if input inputs << input opts[:each].call(game, input) if opts[:each] game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) if opts[:max] && inputs.length >= opts[:max] game.engine.prompt = nil end else game.engine.prompt = nil end if opts[:after] && game.engine.prompt.nil? opts[:after].call(game, inputs) end } } } end class Autocomplete def self.cards_in_hand lambda {|game| lambda {|input| suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil } } end def self.boolean lambda {|game| lambda {|input| %w(Y N).detect {|x| x == input.upcase } || nil } } end end end class Game include Dominion::Util include Dominion::Player attr_accessor :board, :cards, :player, :turn def initialize @cards = {} @turn = 1 self.engine = Dominion::UI::NCurses.new end def player @player ||= { :actions => 1, :buys => 1, :gold => 0, :hand => [], :discard => [], :trash => [], :played => [], :revealed => [], :deck => randomize( [cards[:estate]] * 3 + [cards[:copper]] * 7 ).compact } end def board - @board ||= @cards.keys.map {|x| [card(x)] * 8 } + @board ||= begin + defaults = [:copper, :silver, :gold, :estate, :duchy, :provence, :curse] + (defaults + randomize(@cards.keys - defaults)[0..9]).map {|x| + [card(x)] * ({ + :copper => 60, + :silver => 40, + :gold => 30 + }[x] || 8) + } + end # [card(:copper)] * 60, # [card(:silver)] * 40, # [card(:gold)] * 30, end def card(key) cards[key] || raise("No card #{key}") end def add_card(key, values) key = key.to_sym @cards[key] = add_defaults_to_card(key, values) end def treasure(player) player[:gold] + player[:hand].select {|x| x[:type] == :treasure }.map {|x| raise x.inspect unless x[:gold] x[:gold] }.inject(0) {|a, b| a + b } end def test print_board(board) require 'pp' 5.times { draw_card(player) } print_player(player) play_card(player, :cellar) pp player end attr_accessor :engine def run cleanup(board, player) engine.setup running = true while running skip = false if engine.prompt.nil? if player[:actions] > 0 engine.card_active = lambda {|card| card[:type] == :action && player[:hand].include?(card)} engine.prompt = { :prompt => "action (#{player[:actions]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : player[:hand].detect {|x| [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :accept => lambda {|input| engine.prompt = nil if input play_card(player, input) else player[:actions] = 0 end } } elsif player[:buys] > 0 engine.card_active = lambda {|card| card[:cost] <= treasure(player) } engine.prompt = { :prompt => "buy (#{player[:buys]} left)?", :autocomplete => lambda {|input| suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i } suggest ? suggest[:name] : nil }, :accept => lambda {|input| if input buy_card(board, player, input) else player[:buys] = 0 end engine.prompt = nil } } else # Run the cleanup phase cleanup(board, player) skip = true @turn += 1 end end unless skip ctx = engine.draw(self) engine.step(ctx) end end ensure engine.finalize if engine end def self.instance @instance ||= new end def load_all_cards load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| File.basename(x).split('.')[0..-2].join(".") }) end def load_cards(*args) args.map(&:to_sym).each do |c| require File.dirname(__FILE__) + "/cards/#{c}" add_card(c, CARDS[c]) end end end CARDS = {} end
xaviershay/dominion-solitaire
9c35ba795688b1d5253e0038310a776c64a882aa
Basic action cards: festival, lab, smithy, woodcutter, village
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b14c548 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +debug.log diff --git a/README b/README new file mode 100644 index 0000000..206ea56 --- /dev/null +++ b/README @@ -0,0 +1,13 @@ += Dominion Solitaire +An ncurses Dominion implementation with a focus on lightning quick goldfishing. +You play cards by typing their name with smart autocomplete. +It's a WIP - logic is there to play the game, but virtually no card logic exists yet (i.e there's no cards). + +== Running + +I haven't totally automated some ncurses stuff yet - you may need the following env settings to get things working + + ls /usr/lib/ | grep libncurses # Find your libncurses .dylib + export RUBY_FFI_NCURSES_LIB=libncurses # Tell ffi-ncurses to use the right one + + rake run diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2152a98 --- /dev/null +++ b/Rakefile @@ -0,0 +1,13 @@ +require 'spec/rake/spectask' +Spec::Rake::SpecTask.new do |t| + t.warning = false + t.rcov = false + t.spec_files = FileList['spec/**/*_spec.rb'] +end + +task :default => :spec + +desc "Run the game" +task :run do + exec('ruby lib/run.rb') +end diff --git a/lib/dominion/cards/adventurer.rb b/lib/dominion/cards/adventurer.rb new file mode 100644 index 0000000..46be563 --- /dev/null +++ b/lib/dominion/cards/adventurer.rb @@ -0,0 +1,35 @@ +Dominion::CARDS[:adventurer] = { + :type => :action, + :cost => 6, + :description => 'Reveal until 2T revealed: T to hand, rest to discard', + :behaviour => lambda {|game, card| + player = game.player + revealed = [] + treasure = lambda { + revealed.select {|x| [*x[:type]].include?(:treasure) } + } + + while treasure[].size < 2 && !(player[:deck] + player[:discard]).empty? + game.reveal_card(game.player).tap do |c| + revealed << c if c + end + end + + game.engine.prompt = { + :prompt => "Press enter to continue", + :autocomplete => lambda {|input| nil }, + :accept => lambda {|input| + game.engine.prompt = nil + + treasure[].each do |t| + game.move_card(t, player[:revealed], player[:hand]) + revealed.delete_at(revealed.index(t)) + end + + revealed.each do |c| + game.move_card(c, player[:revealed], player[:discard]) + end + } + } + } +} diff --git a/lib/dominion/cards/bureaucrat.rb b/lib/dominion/cards/bureaucrat.rb new file mode 100644 index 0000000..868f1b8 --- /dev/null +++ b/lib/dominion/cards/bureaucrat.rb @@ -0,0 +1,10 @@ +Dominion::CARDS[:bureaucrat] = { + :cost => 4, + :type => [:action, :attack], + :description => "Gain 1 silver to deck, others put V from hand to deck", + :behaviour => lambda {|game, card| + if card = game.gain_card(game.board, game.player, :silver) + game.move_card(card, game.player[:discard], game.player[:deck]) + end + } +} diff --git a/lib/dominion/cards/cellar.rb b/lib/dominion/cards/cellar.rb new file mode 100644 index 0000000..169a7f1 --- /dev/null +++ b/lib/dominion/cards/cellar.rb @@ -0,0 +1,14 @@ +Dominion::CARDS[:cellar] = { + :type => :action, + :cost => 2, + :actions => 1, + :description => 'Discard X cards, draw X cards', + :behaviour => Dominion::Input.accept_cards( + :strategy => Dominion::Input::Autocomplete.cards_in_hand, + :prompt => lambda {|game, inputs| "discard (%i so far)? " % inputs.length }, + :each => lambda {|game, input| game.discard_card(game.player, input) }, + :after => lambda {|game, inputs| + inputs.length.times { game.draw_card(game.player) } + } + ) +} diff --git a/lib/dominion/cards/chancellor.rb b/lib/dominion/cards/chancellor.rb new file mode 100644 index 0000000..9836bb9 --- /dev/null +++ b/lib/dominion/cards/chancellor.rb @@ -0,0 +1,19 @@ +Dominion::CARDS[:chancellor] = { + :type => :action, + :cost => 3, + :gold => 2, + :behaviour => lambda {|game, card| + game.engine.prompt = { + :prompt => "Discard your deck (y/N)?", + :autocomplete => Dominion::Input::Autocomplete.boolean[game], + :accept => lambda {|input| + if input == 'Y' + game.player[:discard] += game.player[:deck] + game.player[:deck] = [] + end + + game.engine.prompt = nil + } + } + } +} diff --git a/lib/dominion/cards/chapel.rb b/lib/dominion/cards/chapel.rb new file mode 100644 index 0000000..31a457f --- /dev/null +++ b/lib/dominion/cards/chapel.rb @@ -0,0 +1,11 @@ +Dominion::CARDS[:chapel] = { + :type => :action, + :cost => 2, + :description => 'Trash <= 4 cards', + :behaviour => Dominion::Input.accept_cards( + :strategy => Dominion::Input::Autocomplete.cards_in_hand, + :prompt => lambda {|game, inputs| "trash (%i left)?" % (4 - inputs.length) }, + :each => lambda {|game, input| game.trash_card(game.player, input) }, + :max => 4 + ) +} diff --git a/lib/dominion/cards/copper.rb b/lib/dominion/cards/copper.rb new file mode 100644 index 0000000..9a97381 --- /dev/null +++ b/lib/dominion/cards/copper.rb @@ -0,0 +1,5 @@ +Dominion::CARDS[:copper] = { + :type => :treasure, + :gold => 1, + :cost => 0 +} diff --git a/lib/dominion/cards/curse.rb b/lib/dominion/cards/curse.rb new file mode 100644 index 0000000..dfb544b --- /dev/null +++ b/lib/dominion/cards/curse.rb @@ -0,0 +1,4 @@ +Dominion::CARDS[:curse] = { + :type => :victory, + :cost => 0 +} diff --git a/lib/dominion/cards/duchy.rb b/lib/dominion/cards/duchy.rb new file mode 100644 index 0000000..81c7243 --- /dev/null +++ b/lib/dominion/cards/duchy.rb @@ -0,0 +1,4 @@ +Dominion::CARDS[:duchy] = { + :type => :victory, + :cost => 5 +} diff --git a/lib/dominion/cards/estate.rb b/lib/dominion/cards/estate.rb new file mode 100644 index 0000000..20ac2b6 --- /dev/null +++ b/lib/dominion/cards/estate.rb @@ -0,0 +1,4 @@ +Dominion::CARDS[:estate] = { + :type => :victory, + :cost => 2 +} diff --git a/lib/dominion/cards/festival.rb b/lib/dominion/cards/festival.rb new file mode 100644 index 0000000..6baff2c --- /dev/null +++ b/lib/dominion/cards/festival.rb @@ -0,0 +1,7 @@ +Dominion::CARDS[:festival] = { + :cost => 5, + :type => :action, + :actions => 2, + :buys => 1, + :gold => 2 +} diff --git a/lib/dominion/cards/gold.rb b/lib/dominion/cards/gold.rb new file mode 100644 index 0000000..e56b1f0 --- /dev/null +++ b/lib/dominion/cards/gold.rb @@ -0,0 +1,5 @@ +Dominion::CARDS[:gold] = { + :type => :treasure, + :gold => 3, + :cost => 6 +} diff --git a/lib/dominion/cards/laboratory.rb b/lib/dominion/cards/laboratory.rb new file mode 100644 index 0000000..ef77501 --- /dev/null +++ b/lib/dominion/cards/laboratory.rb @@ -0,0 +1,6 @@ +Dominion::CARDS[:laboratory] = { + :cost => 5, + :type => :action, + :actions => 1, + :cards => 2 +} diff --git a/lib/dominion/cards/market.rb b/lib/dominion/cards/market.rb new file mode 100644 index 0000000..d69f7d1 --- /dev/null +++ b/lib/dominion/cards/market.rb @@ -0,0 +1,8 @@ +Dominion::CARDS[:market] = { + :type => :action, + :cost => 5, + :actions => 1, + :cards => 1, + :gold => 1, + :buys => 1 +} diff --git a/lib/dominion/cards/moat.rb b/lib/dominion/cards/moat.rb new file mode 100644 index 0000000..fdf15da --- /dev/null +++ b/lib/dominion/cards/moat.rb @@ -0,0 +1,6 @@ +Dominion::CARDS[:moat] = { + :cost => 2, + :type => [:action, :reaction], + :cards => 2, + :description => "Reveal from your hand to defend an attack" +} diff --git a/lib/dominion/cards/provence.rb b/lib/dominion/cards/provence.rb new file mode 100644 index 0000000..09b326a --- /dev/null +++ b/lib/dominion/cards/provence.rb @@ -0,0 +1,4 @@ +Dominion::CARDS[:provence] = { + :type => :victory, + :cost => 8 +} diff --git a/lib/dominion/cards/silver.rb b/lib/dominion/cards/silver.rb new file mode 100644 index 0000000..fb1ec08 --- /dev/null +++ b/lib/dominion/cards/silver.rb @@ -0,0 +1,5 @@ +Dominion::CARDS[:silver] = { + :type => :treasure, + :gold => 2, + :cost => 3 +} diff --git a/lib/dominion/cards/smithy.rb b/lib/dominion/cards/smithy.rb new file mode 100644 index 0000000..14cc827 --- /dev/null +++ b/lib/dominion/cards/smithy.rb @@ -0,0 +1,5 @@ +Dominion::CARDS[:smithy] = { + :cost => 5, + :type => :action, + :cards => 3 +} diff --git a/lib/dominion/cards/village.rb b/lib/dominion/cards/village.rb new file mode 100644 index 0000000..ec921dd --- /dev/null +++ b/lib/dominion/cards/village.rb @@ -0,0 +1,6 @@ +Dominion::CARDS[:village] = { + :type => :action, + :cost => 3, + :actions => 2, + :cards => 1 +} diff --git a/lib/dominion/cards/woodcutter.rb b/lib/dominion/cards/woodcutter.rb new file mode 100644 index 0000000..b7b46ac --- /dev/null +++ b/lib/dominion/cards/woodcutter.rb @@ -0,0 +1,6 @@ +Dominion::CARDS[:woodcutter] = { + :cost => 3, + :type => :action, + :buys => 1, + :gold => 2 +} diff --git a/lib/dominion/game.rb b/lib/dominion/game.rb new file mode 100644 index 0000000..2f00c12 --- /dev/null +++ b/lib/dominion/game.rb @@ -0,0 +1,338 @@ +require 'dominion/ui' + +module Dominion + module Util + def add_defaults_to_card(name, values) + values = values.dup + values[:key] = name + values[:name] = name.to_s.gsub(/\b('?[a-z])/) { $1.capitalize } + + if [*values[:type]].include?(:action) + existing = values[:behaviour] + values[:behaviour] = lambda do |game, card| + game.player[:actions] += card[:actions].to_i + game.player[:buys] += card[:buys].to_i + game.player[:gold] += card[:gold].to_i + card[:cards].to_i.times do + draw_card(game.player) + end + existing[game, card] if existing + end + end + values + end + + def generate_names!(cards) + cards.each do |key, values| + add_defaults_to_card(key, values) + end + end + + def randomize(array) + array.sort_by { rand } + end + + def print_board(board) + board.each do |pile| + puts "$%i: %i x %s" % [ + pile.first[:cost], + pile.length, + pile.first[:name]] + end + end + + def print_player(player) + puts "Hand: %s" % player[:hand].map {|x| + x[:name] + }.join(", ") + end + end + + module Player + def move_card(card, from, to) + card = from.detect {|x| x[:key] == card[:key] } + + from.delete_at(from.index(card)) + to.unshift(card) + card + end + + def draw_card(player) + if player[:deck].length == 0 + player[:deck] = randomize(player[:discard]) + player[:discard] = [] + end + + player[:hand] << player[:deck].shift unless player[:deck].empty? + end + + def reveal_card(player) + if player[:deck].length == 0 + player[:deck] = randomize(player[:discard]) + player[:discard] = [] + end + + unless player[:deck].empty? + player[:deck].shift.tap do |c| + player[:revealed] << c + end + end + end + + def gain_card(board, player, card_key) + pile = board.detect {|pile| pile[0][:key] == card_key } + pile.shift.tap do |card| + player[:discard] << card + end + end + + def buy_card(board, player, card_name) + pile = board.detect {|pile| pile[0][:name] == card_name.to_s } + pile.shift.tap do |card| + player[:discard] << card + player[:gold] -= card[:cost] + player[:buys] -= 1 + end + end + + def play_card(player, card_name) + card = player[:hand].detect {|x| x[:name] == card_name.to_s } + + player[:hand].delete_at(player[:hand].index(card)) + player[:played] << card + player[:actions] -= 1 + + card[:behaviour][self, card] + end + + def discard_card(player, card_name) + card = player[:hand].detect {|x| x[:name].downcase == card_name.to_s.downcase } + + player[:hand].delete_at(player[:hand].index(card)) + player[:discard] << card + end + + def trash_card(player, card_name) + card = player[:hand].detect {|x| x[:name] == card_name.to_s } + + player[:hand].delete_at(player[:hand].index(card)) + player[:trash] << card + end + + def cleanup(board, player) + player[:discard] += player[:hand] + player[:discard] += player[:played] + player[:hand] = [] + player[:played] = [] + 5.times { draw_card(player) } + player[:actions] = 1 + player[:buys] = 1 + player[:gold] = 0 + end + end + + class Input + def self.accept_cards(opts) + lambda {|game, card| + inputs = [] + + game.engine.prompt = { + :prompt => opts[:prompt].call(game, inputs), + :autocomplete => opts[:strategy].call(game), + :accept => lambda {|input| + if input + inputs << input + opts[:each].call(game, input) if opts[:each] + + game.engine.prompt[:prompt] = opts[:prompt].call(game, inputs) + + if opts[:max] && inputs.length >= opts[:max] + game.engine.prompt = nil + end + else + game.engine.prompt = nil + end + + if opts[:after] && game.engine.prompt.nil? + opts[:after].call(game, inputs) + end + } + } + } + end + + class Autocomplete + def self.cards_in_hand + lambda {|game| + lambda {|input| + suggest = input.length == 0 ? nil : game.player[:hand].detect {|x| + x[:name] =~ /^#{input}/i + } + suggest ? suggest[:name] : nil + } + } + end + + def self.boolean + lambda {|game| + lambda {|input| + %w(Y N).detect {|x| x == input.upcase } || nil + } + } + end + end + end + + + class Game + include Dominion::Util + include Dominion::Player + + attr_accessor :board, :cards, :player, :turn + + def initialize + @cards = {} + @turn = 1 + + self.engine = Dominion::UI::NCurses.new + end + + def player + @player ||= { + :actions => 1, + :buys => 1, + :gold => 0, + :hand => [], + :discard => [], + :trash => [], + :played => [], + :revealed => [], + :deck => randomize( + [cards[:estate]] * 3 + + [cards[:copper]] * 7 + ).compact + } + end + + def board + @board ||= @cards.keys.map {|x| [card(x)] * 8 } +# [card(:copper)] * 60, +# [card(:silver)] * 40, +# [card(:gold)] * 30, + end + + def card(key) + cards[key] || raise("No card #{key}") + end + + def add_card(key, values) + key = key.to_sym + @cards[key] = add_defaults_to_card(key, values) + end + + def treasure(player) + player[:gold] + player[:hand].select {|x| + x[:type] == :treasure + }.map {|x| + raise x.inspect unless x[:gold] + x[:gold] + }.inject(0) {|a, b| + a + b + } + end + + def test + print_board(board) + + require 'pp' + 5.times { draw_card(player) } + print_player(player) + play_card(player, :cellar) + pp player + end + + attr_accessor :engine + def run + cleanup(board, player) + engine.setup + running = true + + while running + skip = false + if engine.prompt.nil? + if player[:actions] > 0 + engine.card_active = lambda {|card| card[:type] == :action && player[:hand].include?(card)} + engine.prompt = { + :prompt => "action (#{player[:actions]} left)?", + :autocomplete => lambda {|input| + suggest = input.length == 0 ? nil : player[:hand].detect {|x| + [*x[:type]].include?(:action) && x[:name] =~ /^#{input}/i + } + suggest ? suggest[:name] : nil + }, + :accept => lambda {|input| + engine.prompt = nil + if input + play_card(player, input) + else + player[:actions] = 0 + end + } + } + elsif player[:buys] > 0 + engine.card_active = lambda {|card| + card[:cost] <= treasure(player) + } + engine.prompt = { + :prompt => "buy (#{player[:buys]} left)?", + :autocomplete => lambda {|input| + suggest = input.length == 0 ? nil : board.map(&:first).detect {|x| + x[:cost] <= treasure(player) && x[:name] =~ /^#{input}/i + } + suggest ? suggest[:name] : nil + }, + :accept => lambda {|input| + if input + buy_card(board, player, input) + else + player[:buys] = 0 + end + engine.prompt = nil + } + } + else + # Run the cleanup phase + cleanup(board, player) + skip = true + @turn += 1 + end + end + + unless skip + ctx = engine.draw(self) + engine.step(ctx) + end + end + ensure + engine.finalize if engine + end + + def self.instance + @instance ||= new + end + + def load_all_cards + load_cards(*Dir[File.dirname(__FILE__) + '/cards/*.rb'].map {|x| + File.basename(x).split('.')[0..-2].join(".") + }) + end + + def load_cards(*args) + args.map(&:to_sym).each do |c| + require File.dirname(__FILE__) + "/cards/#{c}" + add_card(c, CARDS[c]) + end + end + end + CARDS = {} +end diff --git a/lib/dominion/ui.rb b/lib/dominion/ui.rb new file mode 100644 index 0000000..d5dcffb --- /dev/null +++ b/lib/dominion/ui.rb @@ -0,0 +1,297 @@ +require 'ffi-ncurses' + +module Dominion; module UI; end; end; +class Dominion::UI::NCurses + include FFI::NCurses + + attr_accessor :prompt, :input_buffer, :card_active + + def setup + self.prompt = nil + self.input_buffer = '' + + initscr + start_color + noecho + + # set up colour pairs + # Background Foreground + init_pair(0, Colour::BLACK, Colour::BLACK) + init_pair(1, Colour::RED, Colour::BLACK) + init_pair(2, Colour::GREEN, Colour::BLACK) + init_pair(3, Colour::YELLOW, Colour::BLACK) + init_pair(4, Colour::BLUE, Colour::BLACK) + init_pair(5, Colour::MAGENTA, Colour::BLACK) + init_pair(6, Colour::CYAN, Colour::BLACK) + init_pair(7, Colour::WHITE, Colour::BLACK) + + init_pair(8, Colour::BLACK, Colour::BLACK) + init_pair(9, Colour::BLACK, Colour::RED) + init_pair(10, Colour::BLACK, Colour::GREEN) + init_pair(11, Colour::BLACK, Colour::YELLOW) + init_pair(12, Colour::BLACK, Colour::BLUE) + init_pair(13, Colour::BLACK, Colour::MAGENTA) + init_pair(14, Colour::BLACK, Colour::CYAN) + init_pair(15, Colour::BLACK, Colour::WHITE) + end + + def step(ctx) + ch = wgetch(ctx[:input_window]) + + if prompt + case ch + when 10 + prompt[:accept][prompt[:autocomplete][input_buffer]] + self.input_buffer = '' + when 127 + self.input_buffer = input_buffer[0..-2] + else + self.input_buffer += ch.chr + end + end + end + + def finalize + endwin + end + + def draw(game, ctx = {}) + ctx[:windows] ||= {} + curs_set 0 + refresh + + drawn = [{ + :coords => [14, 80, 0, 0], + :title => 'Board', + :draw => lambda do |window, game| + bold_with_color = lambda do |color, text| + color_index = { + :white => 0, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + }[color] || raise("Unknown color: #{color}") + wattr_set window, A_BOLD, color_index, nil + + waddstr(window, text.to_s) + end + print_with_color = lambda do |color, text| + color_index = { + :white => 0, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + }[color] || raise("Unknown color: #{color}") + wattr_set window, A_NORMAL, color_index, nil + + waddstr(window, text.to_s) + end + + type_char = [ + [:reaction, 'R'], + [:attack, 'X'], + [:treasure, 'T'], + [:victory, 'V'], + [:action, 'A'] + ] + + max_name_length = game.board.map {|pile| + pile[0][:name].length + }.max + + header, body = game.board.partition {|x| + [ + :copper, + :silver, + :gold, + :estate, + :duchy, + :provence, + :curse + ].include?(x.first[:key]) + } + + header.each_with_index do |pile, i| + card = pile.first + + print_with_color[:white, ' '] if i > 0 + print_with_color[:yellow, card[:cost]] + print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] + print_with_color[:blue, pile.size] + print_with_color[:white, " %s" % card[:name]] + end +print_with_color[:white, "\n"] + body.sort_by {|x| [x[0][:cost], x[0][:name]] }.each do |pile| + card = pile.first + + print_with_color[:white, ' '] + print_with_color[:yellow, card[:cost]] + print_with_color[:red, type_char.detect {|x| [*card[:type]].include?(x[0]) }[1]] + print_with_color[:blue, '%-2i' % pile.size] + if card_active?(card) + bold_with_color[:white, " %-#{max_name_length}s " % card[:name]] + else + print_with_color[:white, " %-#{max_name_length}s " % card[:name]] + end + + print_with_color[:cyan_back, card[:cards] || ' '] + print_with_color[:green_back, card[:actions] || ' '] + print_with_color[:magenta_back, card[:buys] || ' '] + print_with_color[:yellow_back, card[:gold] || ' '] + + print_with_color[:white, " %-#{max_name_length}s\n" % card[:description]] + end + end + }, { + :title => "Turn %i (%i Action, %i Buy, %i Treasure, %i Discard, %i Deck)" % [ + game.turn, + game.player[:actions], + game.player[:buys], + game.treasure(game.player), + game.player[:discard].length, + game.player[:deck].length + ], + :coords => [10, 80, 14, 0], + :draw => lambda do |window, game| + bold_with_color = lambda do |color, text| + color_index = { + :white => 0, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + }[color] || raise("Unknown color: #{color}") + wattr_set window, A_BOLD, color_index, nil + + waddstr(window, text.to_s) + end + print_with_color = lambda do |color, text| + color_index = { + :white => 0, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + }[color] || raise("Unknown color: #{color}") + wattr_set window, A_NORMAL, color_index, nil + + waddstr(window, text.to_s) + end + + print_with_color[:white, "Hand: "] + line_length = 6 + game.player[:hand].each_with_index do |card, index| + suffix = index == game.player[:hand].length - 1 ? '' : ', ' + if card_active?(card) + bold_with_color[:white, card[:name] + suffix] + else + print_with_color[:white, card[:name] + suffix] + end + line_length += (card[:name] + suffix).length + end + + # TODO: print ' ' doesn't work :( + print_with_color[:white, " " * (77 - line_length)] + print_with_color[:white, "\n"] + played = "Played: %s" % game.player[:played].map {|x| x[:name] }.join(", ") + print_with_color[:white, played] + print_with_color[:white, " " * (77 - played.length)] + print_with_color[:white, "\n"] + + unless game.player[:revealed].empty? + revealed = "Revealed: %s\n" % game.player[:revealed].map {|x| x[:name] }.join(", ") + print_with_color[:white, revealed] + print_with_color[:white, " " * (77 - revealed.length)] + end + + end + }, { + :coords => [1, 80, 24, 0], + :border => false, + :draw => lambda do |window, game| + print_with_color = lambda do |color, text| + color_index = { + :white => 7, + :yellow => 3, + :blue => 4, + :red => 1, + :cyan_back => 14, + :green_back => 10, + :magenta_back => 13, + :yellow_back => 11 + }[color] || raise("Unknown color: #{color}") + wattr_set window, A_NORMAL, color_index, nil + + waddstr(window, text.to_s) + end + + if prompt + #print_with_color[:yellow_back, "%-80s" % ""] + + suggest = prompt[:autocomplete][input_buffer].to_s + + print_with_color[:yellow_back, "%s %s" % [ + prompt[:prompt], + input_buffer]] + + fill = suggest[input_buffer.length..-1] + + if fill && fill.length > 0 + print_with_color[:red, "%s" % fill] + end + else + print_with_color[:green_back, "%-80s" % " "] + end + end + }].map do |window| + window[:border] = true unless window.has_key?(:border) + + c = window[:coords] + board_frame = (ctx[:windows][[:outer] + c] ||= newwin(*c)) + + if window[:border] + board = (ctx[:windows][[:inner] + c] ||= newwin(c[0] - 2, c[1] - 2, c[2] + 1, c[3] + 1)) + + window[:draw][board, game] + + wattr_set board_frame, A_NORMAL, 7, nil + box(board_frame, c[2], c[3]) + wmove(board_frame, 0, 2) + waddstr(board_frame, "| #{window[:title]} |") + wrefresh(board_frame) + wrefresh(board) + { + :frame => board_frame, + :inner => board + } + else + window[:draw][board_frame, game] + wrefresh(board_frame) + { + :frame => nil, + :inner => board_frame + } + end + end + + {:input_window => drawn[0][:inner]} + end + + def card_active?(card) + (self.card_active || lambda { false }).call(card) + end +end diff --git a/lib/run.rb b/lib/run.rb new file mode 100644 index 0000000..f723e0d --- /dev/null +++ b/lib/run.rb @@ -0,0 +1,13 @@ +$LOAD_PATH.unshift(File.dirname(__FILE__)) + +def log(message) + @log ||= File.open('debug.log', 'a') + @log.puts message + @log.flush +end + +require 'dominion/game' + +game = Dominion::Game.new +game.load_all_cards +game.run diff --git a/lib/ui-test.rb b/lib/ui-test.rb new file mode 100644 index 0000000..86901c2 --- /dev/null +++ b/lib/ui-test.rb @@ -0,0 +1,200 @@ +#!/usr/bin/env ruby +# +# Sean O'Halpin, 2009-02-15 +# + +class Card < Struct.new(:name, :buys, :actions, :cards, :gold, :extra) +end + +cards = [ + Card.new("Smithy", 0, 0, 3, 0, ""), + Card.new("Cellar", 0, 1, 0, 0, "Discard X cards, +X cards"), + Card.new("Chapel", 0, 0, 0, 0, "Trash <= 4 cards"), + Card.new("Workshop", 0, 0, 0, 0, "Gain a card <= 4"), + Card.new("Chancellor", 0, 0, 0, 2, "You may put your deck into your discard"), + Card.new("Council Room", 1, 0, 4, 0, "Each other player draws a card"), + Card.new("Mine", 0,0,0, 0, "Trash a T, gain a T costing <= 3 more to your hand"), + Card.new("Cellar", 0, 1, 0, 0, "Discard X cards, +X cards"), + Card.new("Chapel", 0, 0, 0, 0, "Trash <= 4 cards"), + Card.new("Workshop", 0, 0, 0, 0, "Gain a card <= 4") +] + +require 'rubygems' +require 'ffi-ncurses' +include FFI::NCurses + +initscr +begin + # turn cursor off + curs_set 0 +# + board = newwin(14, 80, 0, 0) + +# initscr +# curs_set 0 + #win = newwin(6, 12, 15, 15) +# win = newwin(1, 12, 15, 15) +# box(win, 0, 0) +# inner_win = newwin(4, 10, 16, 16) +# waddstr(inner_win, (["Hello window!"] * 5).join(' ')) +# wrefresh(win) +# wrefresh(inner_win) +# ch = wgetch(inner_win) +# raise + + # initialize colour + start_color + + # set up colour pairs + # Background Foreground + init_pair(0, Colour::BLACK, Colour::BLACK) + init_pair(1, Colour::RED, Colour::BLACK) + init_pair(2, Colour::GREEN, Colour::BLACK) + init_pair(3, Colour::YELLOW, Colour::BLACK) + init_pair(4, Colour::BLUE, Colour::BLACK) + init_pair(5, Colour::MAGENTA, Colour::BLACK) + init_pair(6, Colour::CYAN, Colour::BLACK) + init_pair(7, Colour::WHITE, Colour::BLACK) + + init_pair(8, Colour::BLACK, Colour::BLACK) + init_pair(9, Colour::BLACK, Colour::RED) + init_pair(10, Colour::BLACK, Colour::GREEN) + init_pair(11, Colour::BLACK, Colour::YELLOW) + init_pair(12, Colour::BLACK, Colour::BLUE) + init_pair(13, Colour::BLACK, Colour::MAGENTA) + init_pair(14, Colour::BLACK, Colour::CYAN) + init_pair(15, Colour::BLACK, Colour::WHITE) +# +# 0.upto(15) do |i| +# attr_set A_NORMAL, i, nil +# waddch(board, ?A + i) +# end +# waddstr board, "\n" +# +# + print_attr = lambda do |i| + i == 0 ? + wprintw(board, ' ') : + wprintw(board, "%i", :int, i) + end + wprintw(board, "\n") + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "0") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "T") + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Copper') + wattr_set board, A_NORMAL, 7, nil + + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "3") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "T") + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Silver') + + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "6") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "T") + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Gold') + + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "2") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "V") + wattr_set board, A_NORMAL, 4, nil + wprintw(board, "%i", :int, 8) + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Estate') + + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "5") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "V") + wattr_set board, A_NORMAL, 4, nil + wprintw(board, "%i", :int, 8) + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Dutchy') + + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "8") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "V") + wattr_set board, A_NORMAL, 4, nil + wprintw(board, "%i", :int, 8) + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Provence') + + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "0") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "V") + wattr_set board, A_NORMAL, 4, nil + wprintw(board, "%i", :int, 8) + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " %s", :string, 'Curse') + + wprintw(board, "\n") + wprintw(board, "\n") + + cards.each do |card| + wattr_set board, A_NORMAL, 7, nil + wprintw(board, " ") + wattr_set board, A_NORMAL, 3, nil + wprintw(board, "2") + wattr_set board, A_NORMAL, 1, nil + wprintw(board, "A") + wattr_set board, A_NORMAL, 4, nil + wprintw(board, "%i ", :int, 8) + wattr_set board, A_NORMAL, 7, nil + wprintw(board, "%-15s", :string, card.name) + wattr_set board, A_NORMAL, 14, nil + print_attr[card.cards] + wattr_set board, A_NORMAL, 10, nil + print_attr[card.actions] + wattr_set board, A_NORMAL, 13, nil + print_attr[card.buys] + wattr_set board, A_NORMAL, 11, nil + print_attr[card.gold] + wattr_set board, A_NORMAL, 0, nil + wprintw(board," %s", :string, card.extra) + wprintw(board, "\n") + end +# waddstr board, " " +# 0.upto(15) do |i| +# wattr_set board, A_NORMAL, i, nil +# waddch(board, ?A + i) +# end +# waddstr board, "\n" + wattr_set board, A_NORMAL, 7, nil + box(board, 0, 0) +# +# 0.upto(15) do |i| +# attr_set A_NORMAL, i, nil +# addch(?A + i) +# end + + # add character and attribute together +# addch(?Z | COLOR_PAIR(1)) # red + + +# waddstr board, "Press any key" + + # display and pause for key press + wrefresh(board) + ch = wgetch(board) +ensure + endwin + puts can_change_color +end + diff --git a/spec/cards/action_spec.rb b/spec/cards/action_spec.rb new file mode 100644 index 0000000..a07adf0 --- /dev/null +++ b/spec/cards/action_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +[:woodcutter, :smithy, :festival, :laboratory, :market, :village].each do |c| + describe_card c do + it_should_behave_like 'an action card' + end +end diff --git a/spec/cards/adventurer_spec.rb b/spec/cards/adventurer_spec.rb new file mode 100644 index 0000000..46383a3 --- /dev/null +++ b/spec/cards/adventurer_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' + +describe_card :adventurer do + it_should_behave_like 'an action card' + + describe 'when played' do + it 'reveals cards until 2 treasures are revealed, then puts them both in hand and discards the rest' do + deck cards(:estate, 1) + cards(:copper, 2) + + playing_card + + hand.should have_cards(cards(:copper, 2)) + discard.should have_cards(cards(:estate, 1)) + end + + it 'aborts if 2 treasures cannot be found' do + deck cards(:estate, 1) + cards(:copper, 1) + + playing_card + + hand.should have_cards(cards(:copper, 1)) + discard.should have_cards(cards(:estate, 1)) + end + end +end diff --git a/spec/cards/bureaucrat_spec.rb b/spec/cards/bureaucrat_spec.rb new file mode 100644 index 0000000..ee2e261 --- /dev/null +++ b/spec/cards/bureaucrat_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe_card :bureaucrat, :needs_cards => [:silver] do + it_should_behave_like 'an action card' + it_should_behave_like 'an attack card' + + describe 'when played' do + it 'puts a silver card on the top of my deck' do + deck [] + + playing_card + + deck.should have_cards(cards(:silver, 1)) + end + + it 'does not gain a silver if no more are left in the pile' do + end + + it 'forces each other player to reveal a victory card and put it on top of their deck' do + # Unimplemented - not relevant for solitaire + end + end +end diff --git a/spec/cards/cellar_spec.rb b/spec/cards/cellar_spec.rb new file mode 100644 index 0000000..7a9809a --- /dev/null +++ b/spec/cards/cellar_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe_card :cellar do + it_should_behave_like 'an action card' + + describe 'when I discard 0 cards' do + before do + deck cards(:copper, 1) + + playing_card(subject) + end + + it 'does not draw any cards' do + game.should_not have_prompt + hand.should be_empty + deck.should have_cards(cards(:copper, 1)) + end + end + + describe 'when I discard X cards' do + let(:x) { 2 } + + before do + deck cards(:copper, x) + hand cards(:estate, x + 1) + + playing_card(subject) do + x.times { + game.should have_prompt_with_autocomplete(:cards_in_hand) + input 'estate' + } + game.should have_prompt_with_autocomplete(:cards_in_hand) + end + end + + it 'draws X cards' do + hand.should have_cards(cards(:copper, x) + cards(:estate, 1)) + deck.should be_empty + end + end +end diff --git a/spec/cards/chancellor_spec.rb b/spec/cards/chancellor_spec.rb new file mode 100644 index 0000000..268d5d9 --- /dev/null +++ b/spec/cards/chancellor_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe_card :chancellor do + it_should_behave_like 'an action card' + + describe 'when playing' do + it 'allows me to discard my deck' do + deck cards(:copper, 1) + + playing_card do + input 'y' + end + game.should_not have_prompt + + deck.should have_cards([]) + discard.should have_cards(cards(:copper, 1)) + end + + it 'does not discard my deck by default' do + deck cards(:copper, 1) + + playing_card + + game.should_not have_prompt + discard.should have_cards([]) + deck.should have_cards(cards(:copper, 1)) + end + end +end diff --git a/spec/cards/chapel_spec.rb b/spec/cards/chapel_spec.rb new file mode 100644 index 0000000..ed1a1b5 --- /dev/null +++ b/spec/cards/chapel_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe_card :chapel do + it_should_behave_like 'an action card' + + describe 'when I input 4 cards' do + before do + hand cards(:copper, 5) + + playing_card(subject) do + 4.times { + game.should have_prompt_with_autocomplete(:cards_in_hand) + input 'copper' + } + game.should_not have_prompt # Max 4 cards + end + end + + it 'trashes those cards' do + hand.should have_cards(cards(:copper, 1)) + trash.should have_cards(cards(:copper, 4)) + end + end +end diff --git a/spec/cards/common/action_spec.rb b/spec/cards/common/action_spec.rb new file mode 100644 index 0000000..ba7dee5 --- /dev/null +++ b/spec/cards/common/action_spec.rb @@ -0,0 +1,26 @@ +describe 'an action card', :shared => true do + it 'has a type of :action' do + [*subject[:type]].should include(:action) + end + + describe 'when played' do + before { playing_card } + + it "increments the player actions by it's action count" do + player[:actions].should == subject[:actions].to_i + 1 + end + + it "increments the player buys by it's buy count" do + player[:buys].should == subject[:buys].to_i + 1 + end + + it "increments the player gold by it's gold count" do + player[:gold].should == subject[:gold].to_i + end + + it "draws at least as many cards as it's card count" do + # Some cards draw via other means, so can draw more + player[:hand].size.should >= subject[:cards].to_i + end + end +end diff --git a/spec/cards/common/attack_spec.rb b/spec/cards/common/attack_spec.rb new file mode 100644 index 0000000..dfa8677 --- /dev/null +++ b/spec/cards/common/attack_spec.rb @@ -0,0 +1,5 @@ +describe 'an attack card', :shared => true do + it 'has a type of :attack' do + [*subject[:type]].should include(:attack) + end +end diff --git a/spec/cards/common/reaction_spec.rb b/spec/cards/common/reaction_spec.rb new file mode 100644 index 0000000..f118e42 --- /dev/null +++ b/spec/cards/common/reaction_spec.rb @@ -0,0 +1,5 @@ +describe 'a reaction card', :shared => true do + it 'has a type of :reaction' do + [*subject[:type]].should include(:reaction) + end +end diff --git a/spec/cards/common/treasure_spec.rb b/spec/cards/common/treasure_spec.rb new file mode 100644 index 0000000..ade72c3 --- /dev/null +++ b/spec/cards/common/treasure_spec.rb @@ -0,0 +1,5 @@ +describe 'a treasure card', :shared => true do + it 'has a type of :treasure' do + [*subject[:type]].should include(:treasure) + end +end diff --git a/spec/cards/common/victory_spec.rb b/spec/cards/common/victory_spec.rb new file mode 100644 index 0000000..f02fa2b --- /dev/null +++ b/spec/cards/common/victory_spec.rb @@ -0,0 +1,5 @@ +describe 'a victory card', :shared => true do + it 'has a type of :victory' do + [*subject[:type]].should include(:victory) + end +end diff --git a/spec/cards/copper_spec.rb b/spec/cards/copper_spec.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/cards/market_spec.rb b/spec/cards/market_spec.rb new file mode 100644 index 0000000..6c6f210 --- /dev/null +++ b/spec/cards/market_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe_card :market do + it_should_behave_like 'an action card' +end diff --git a/spec/cards/moat_spec.rb b/spec/cards/moat_spec.rb new file mode 100644 index 0000000..e8fd786 --- /dev/null +++ b/spec/cards/moat_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +describe_card :moat do + it_should_behave_like 'an action card' + it_should_behave_like 'a reaction card' +end diff --git a/spec/cards/treasure_spec.rb b/spec/cards/treasure_spec.rb new file mode 100644 index 0000000..80b2221 --- /dev/null +++ b/spec/cards/treasure_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +[:copper, :silver, :gold].each do |name| + describe_card name do + it_should_behave_like 'a treasure card' + end +end diff --git a/spec/cards/victory_spec.rb b/spec/cards/victory_spec.rb new file mode 100644 index 0000000..ae48bad --- /dev/null +++ b/spec/cards/victory_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +[:estate, :duchy, :provence, :curse].each do |name| + describe_card name do + it_should_behave_like 'a victory card' + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cab68e7 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,124 @@ +require 'spec' + +$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) +require 'dominion/game' +require File.expand_path(File.dirname(__FILE__) + '/cards/common/action_spec') +require File.expand_path(File.dirname(__FILE__) + '/cards/common/attack_spec') + +class Proc + def inspect + "[PROC]" + end +end + +Spec::Matchers.define :have_prompt_with_autocomplete do |autocomplete_strategy| + match do |game| + game.engine.prompt + # TODO: Check auto complete + begin + old_player = game.player.dup + + game.player[:deck] = [game.card(:estate)] + game.player[:hand] = [game.card(:copper)] + game.engine.prompt[:autocomplete]['co'].should == 'Copper' + game.engine.prompt[:autocomplete]['es'].should == nil + game.engine.prompt[:autocomplete]['ce'].should == nil + ensure + game.player = old_player + end + end + + failure_message_for_should do |game| + "expected a prompt with autocomplete strategy :#{autocomplete_strategy}" + end +end + +Spec::Matchers.define :have_prompt do + match do |game| + game.engine.prompt + end +end + +Spec::Matchers.define :have_cards do |cards| + match do |pile| + keys(pile) == keys(cards) + end + + failure_message_for_should do |pile| + "expected #{keys(pile).inspect} to be #{keys(cards).inspect}" + end + + def keys(pile) + pile.map {|x| x[:key] }.sort_by(&:to_s) + end +end + +module CardMacros + def game_with_cards(*cards) + @game = Dominion::Game.new.tap do |game| + game.load_cards(*cards + [:copper, :estate]) + end + end + + def game + @game + end + + def card(key) + @game.card(key) + end + + def cards(key, n) + [card(key)] * n + end + + def input(key) + prompt = @game.engine.prompt + + prompt[:accept][prompt[:autocomplete][key]] if prompt + end + + def playing_card(card = nil) + card ||= subject + card[:behaviour][@game, subject] + yield if block_given? + input '' + end + + def player + @game.player + end + + def deck(cards = nil) + player[:deck] = cards || player[:deck] + end + + def hand(cards = nil) + player[:hand] = cards || player[:hand] + end + + def trash(cards = nil) + player[:trash] = cards || player[:trash] + end + + def discard(cards = nil) + player[:discard] = cards || player[:discard] + end +end + + +Spec::Runner.configure do |config| + config.include CardMacros +end + +def describe_card(key, opts = {}, &block) + describe(key.to_s) do + subject { card(key) } + + before do + game_with_cards(*[key] + (opts[:needs_cards] || [])) + end + + instance_eval(&block) + end +end diff --git a/ui-mock.txt b/ui-mock.txt new file mode 100644 index 0000000..814a9a8 --- /dev/null +++ b/ui-mock.txt @@ -0,0 +1,20 @@ +--- Board --------- +T0 8 Copper T3 8 Silver T6 8 Gold +V2 8 Estate V5 8 Duchy V8 8 Province +V4 8 Gardens Worth 1 VP per 10 cards in your deck, rounded down +A2 8 Cellar 1 Discard X cards, +X cards +A2 8 Chapel Trash <= 4 cards +A3 8 Workshop Gain a card <= 4 +A3 8 Chancellor 2 You may put your deck into your discard +A4 8 Mine Trash a T, gain a T costing <= 3 more to your hand +A4 8 Smithy 3 +A5 8 Council Room 4 1 Each other player draws a card +---------------------- ++- Your Turn (1 Action, 1 Buy, 2 Treasure, 5 Deck) +| Hand: Copper, Copper, Estate, Council Room, Mine, Estate, Estate, +| Smithy +| Played: Council Room +| Bought: Mine +| +| 1 action left [Council Room]? C +--------------------------
devfort/hostsetup
03a7d4f30a1643fd6eb085d57d0966246b02ed04
More auto-sites & their DNS.
diff --git a/apache2/sites-available/bugle b/apache2/sites-available/bugle new file mode 100644 index 0000000..7b3ff63 --- /dev/null +++ b/apache2/sites-available/bugle @@ -0,0 +1,50 @@ +<VirtualHost *:80> + ServerName bugle.fort + ServerAlias twitter.com + ServerAlias api.twitter.com + ServerAlias search.twitter.com + ServerAlias foursquare.com + ServerAlias api.foursquare.com + WSGIPassAuthorization On + WSGIScriptAlias / /home/bugle/releases/current/bugle_project/configs/live/bugle.wsgi + ErrorLog /var/log/apache2/bugle-error.log + CustomLog /var/log/apache2/bugle-access.log combined +</VirtualHost> + +<IfModule mod_ssl.c> +<VirtualHost *:443> + ServerName bugle.fort + ServerAlias twitter.com + ServerAlias api.twitter.com + ServerAlias search.twitter.com + WSGIPassAuthorization On + WSGIScriptAlias / /home/bugle/releases/current/bugle_project/configs/live/bugle.wsgi + ErrorLog /var/log/apache2/bugle-error.log + CustomLog /var/log/apache2/bugle-access.log combined + SSLEngine on + # SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem + # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key + SSLCertificateFile /etc/ssl/api.twitter.com.pem + SSLCertificateKeyFile /etc/ssl/api.twitter.com.pem + BrowserMatch ".*MSIE.*" \ + nokeepalive ssl-unclean-shutdown \ + downgrade-1.0 force-response-1.0 +</VirtualHost> +</IfModule> + +<IfModule mod_ssl.c> +<VirtualHost *:443> + ServerName foursquare.com + ServerAlias api.foursquare.com + WSGIPassAuthorization On + WSGIScriptAlias / /home/bugle/bugle_project/bugle.wsgi + ErrorLog /var/log/apache2/fortsquare-error.log + CustomLog /var/log/apache2/fortsquare-access.log combined + SSLEngine on + SSLCertificateFile /etc/ssl/certs/ssl-cert-foursquare.pem + SSLCertificateKeyFile /etc/ssl/private/ssl-cert-foursquare.key + BrowserMatch ".*MSIE.*" \ + nokeepalive ssl-unclean-shutdown \ + downgrade-1.0 force-response-1.0 +</VirtualHost> +</IfModule> diff --git a/apache2/sites-available/default b/apache2/sites-available/default new file mode 100644 index 0000000..9cb434b --- /dev/null +++ b/apache2/sites-available/default @@ -0,0 +1,43 @@ +<VirtualHost *:80> + ServerName clonque.fort + ServerAlias core.fort + ServerAdmin webmaster@localhost + + DocumentRoot /var/www/ + <Directory /> + Options FollowSymLinks + AllowOverride None + </Directory> + <Directory /var/www/> + Options Indexes FollowSymLinks MultiViews + AllowOverride None + Order allow,deny + allow from all + </Directory> + + ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ + <Directory "/usr/lib/cgi-bin"> + AllowOverride None + Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch + Order allow,deny + Allow from all + </Directory> + + ErrorLog /var/log/apache2/error.log + + # Possible values include: debug, info, notice, warn, error, crit, + # alert, emerg. + LogLevel info + + CustomLog /var/log/apache2/access.log combined + + Alias /doc/ "/usr/share/doc/" + <Directory "/usr/share/doc/"> + Options Indexes MultiViews FollowSymLinks + AllowOverride None + Order deny,allow + Deny from all + Allow from 127.0.0.0/255.0.0.0 ::1/128 + </Directory> + +</VirtualHost> diff --git a/apache2/sites-available/extra b/apache2/sites-available/extra index b2f48c8..c463790 100644 --- a/apache2/sites-available/extra +++ b/apache2/sites-available/extra @@ -1,29 +1,32 @@ -<VirtualHost *:80> - ServerName debian.fort - Alias /debian "/home/debian/data/mirror/" - <Directory /home/debian/data/mirror/> - Options +ExecCGI +FollowSymLinks +Indexes - Order allow,deny - allow from all - </Directory> -</VirtualHost> - <VirtualHost *:80> ServerName ubuntu.fort Alias /ubuntu "/home/ubuntu/data/mirror/archive.ubuntu.com/ubuntu/" <Directory /home/ubuntu/data/mirror/> Options +ExecCGI +FollowSymLinks +Indexes Order allow,deny allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerName assets.fort Alias /assets "/home/assets/" <Directory /home/assets/> Options +ExecCGI +FollowSymLinks +Indexes Order allow,deny allow from all </Directory> </VirtualHost> + +VirtualHost *:80> + ServerName pypi.fort + ServerAlias pypi.python.org + DocumentRoot /home/assets/pypi + Alias /simple /home/assets/pypi + <Directory /home/assets/pypi/> + Options Indexes FollowSymLinks MultiViews + AllowOverride None + Order allow,deny + allow from all + </Directory> +</VirtualHost> diff --git a/bind/db.fort b/bind/db.fort index 333667b..99f27a9 100644 --- a/bind/db.fort +++ b/bind/db.fort @@ -1,20 +1,21 @@ $TTL 604800 @ IN SOA localhost. root.localhost. ( 1 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ; Negative Cache TTL ) @ IN NS 10.0.0.1 @ IN NS 10.0.0.2 clonque IN A 10.0.0.1 knockbrex IN A 10.0.0.2 akron IN A 10.0.0.5 hindenburg IN A 10.0.0.6 core IN CNAME clonque assets IN CNAME clonque stage IN CNAME clonque bugle IN CNAME clonque +pypi IN CNAME clonque
devfort/hostsetup
1556c956b7ab9716f9c9a54dac4e0f8f43bc4b8b
Some useful apache-ness.
diff --git a/apache2/sites-available/extra b/apache2/sites-available/extra new file mode 100644 index 0000000..b2f48c8 --- /dev/null +++ b/apache2/sites-available/extra @@ -0,0 +1,29 @@ +<VirtualHost *:80> + ServerName debian.fort + Alias /debian "/home/debian/data/mirror/" + <Directory /home/debian/data/mirror/> + Options +ExecCGI +FollowSymLinks +Indexes + Order allow,deny + allow from all + </Directory> +</VirtualHost> + +<VirtualHost *:80> + ServerName ubuntu.fort + Alias /ubuntu "/home/ubuntu/data/mirror/archive.ubuntu.com/ubuntu/" + <Directory /home/ubuntu/data/mirror/> + Options +ExecCGI +FollowSymLinks +Indexes + Order allow,deny + allow from all + </Directory> +</VirtualHost> + +<VirtualHost *:80> + ServerName assets.fort + Alias /assets "/home/assets/" + <Directory /home/assets/> + Options +ExecCGI +FollowSymLinks +Indexes + Order allow,deny + allow from all + </Directory> +</VirtualHost>
devfort/hostsetup
3054c6d03867a1b46df451c02e0d9df5a9b6805d
Two-use interfaces file; either run dhcp locally and ifup eth0 (which is auto-hotplug), or stop dhcp locally and ifup eth0=dhcp
diff --git a/network/interfaces b/network/interfaces new file mode 100644 index 0000000..1420092 --- /dev/null +++ b/network/interfaces @@ -0,0 +1,15 @@ +# This file describes the network interfaces available on your system +# and how to activate them. For more information, see interfaces(5). + +# The loopback network interface +auto lo +iface lo inet loopback + +# The primary network interface +allow-hotplug eth0 +iface eth0 inet static + address 10.0.0.1 + netmask 255.255.255.0 + broadcast 10.0.0.255 + +iface dhcp inet dhcp
devfort/hostsetup
4bf0e4f5d15ac6fee776cc3047cc661795606250
Add a router into the DHCP configuration, since some setups (notably niobe) react poorly to there not being one. (Probably due to a buggy post-up hook.)
diff --git a/dhcp3/dhcpd.conf b/dhcp3/dhcpd.conf index 804bf29..7fdd48d 100644 --- a/dhcp3/dhcpd.conf +++ b/dhcp3/dhcpd.conf @@ -1,10 +1,11 @@ ddns-update-style none; option domain-name "fort"; option domain-name-servers 10.0.0.1 10.0.0.2; +option routers 10.0.0.1; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.25 10.0.0.250; }
devfort/hostsetup
f5fbcd99a96c4da99845757e9ac36a0e8a9d7af9
Use the second NS.
diff --git a/dhcp3/dhcpd.conf b/dhcp3/dhcpd.conf index 6f850de..804bf29 100644 --- a/dhcp3/dhcpd.conf +++ b/dhcp3/dhcpd.conf @@ -1,10 +1,10 @@ ddns-update-style none; option domain-name "fort"; -option domain-name-servers 10.0.0.1; +option domain-name-servers 10.0.0.1 10.0.0.2; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.25 10.0.0.250; }
devfort/hostsetup
59cbe321e1664f3f3b05e456f9f6b2733e88d468
Add a second NS entry, using knockbrex.
diff --git a/bind/db.fort b/bind/db.fort index df5e223..2a3feee 100644 --- a/bind/db.fort +++ b/bind/db.fort @@ -1,19 +1,20 @@ $TTL 604800 @ IN SOA localhost. root.localhost. ( 1 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ; Negative Cache TTL ) @ IN NS 10.0.0.1 +@ IN NS 10.0.0.2 clonque IN A 10.0.0.1 knockbrex IN A 10.0.0.2 core1 IN A 10.0.0.3 core2 IN A 10.0.0.4 akron IN A 10.0.0.5 hindenburg IN A 10.0.0.6 core IN CNAME core1 assets IN CNAME clonque
devfort/hostsetup
3bf96dbd89b6e7cc33e90b0ee413fe9a29a9975c
Fix spelling mistake.
diff --git a/dhcp3/dhcpd.conf b/dhcp3/dhcpd.conf index 4fefd7c..6f850de 100644 --- a/dhcp3/dhcpd.conf +++ b/dhcp3/dhcpd.conf @@ -1,10 +1,10 @@ ddns-update-style none; option domain-name "fort"; option domain-name-servers 10.0.0.1; -default-least-time 600; +default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.25 10.0.0.250; }
devfort/hostsetup
6d447b7fbe8f662c049e46d57889dd00384db1dc
Some useful files in setting up (physical) /dev/fort host machines.
diff --git a/bind/db.fort b/bind/db.fort new file mode 100644 index 0000000..df5e223 --- /dev/null +++ b/bind/db.fort @@ -0,0 +1,19 @@ +$TTL 604800 +@ IN SOA localhost. root.localhost. ( + 1 ; Serial + 604800 ; Refresh + 86400 ; Retry + 2419200 ; Expire + 604800 ; Negative Cache TTL + ) + +@ IN NS 10.0.0.1 +clonque IN A 10.0.0.1 +knockbrex IN A 10.0.0.2 +core1 IN A 10.0.0.3 +core2 IN A 10.0.0.4 +akron IN A 10.0.0.5 +hindenburg IN A 10.0.0.6 + +core IN CNAME core1 +assets IN CNAME clonque diff --git a/bind/named.conf.local b/bind/named.conf.local new file mode 100644 index 0000000..de35f26 --- /dev/null +++ b/bind/named.conf.local @@ -0,0 +1,4 @@ +zone "fort." { + type master; + file "/etc/bind/db.fort"; +}; diff --git a/bind/named.conf.options b/bind/named.conf.options new file mode 100644 index 0000000..cecf6e4 --- /dev/null +++ b/bind/named.conf.options @@ -0,0 +1,6 @@ +options { + directory "/var/cache/bind"; + auth-nxdomain no; + listen-on-v6 { any; }; + recursion no; +}; diff --git a/dhcp3/dhcpd.conf b/dhcp3/dhcpd.conf new file mode 100644 index 0000000..4fefd7c --- /dev/null +++ b/dhcp3/dhcpd.conf @@ -0,0 +1,10 @@ +ddns-update-style none; +option domain-name "fort"; +option domain-name-servers 10.0.0.1; +default-least-time 600; +max-lease-time 7200; +authoritative; +log-facility local7; +subnet 10.0.0.0 netmask 255.255.255.0 { + range 10.0.0.25 10.0.0.250; +}
infused/stater
c4c471e4dfd86acbd3a50d6e66762803a4aee2ed
remove deprecated test_files
diff --git a/stater.gemspec b/stater.gemspec index 1af0c89..92e938e 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,24 +1,23 @@ lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] - s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] s.license = 'MIT' s.required_rubygems_version = '>= 1.8.0' s.add_development_dependency 'rspec' s.add_development_dependency 'nokogiri' end
infused/stater
a83add65dd37134b01f336f0e8e14121c5bad3af
remove travisci config
diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b548841..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -branches: - only: - - master -language: ruby -rvm: - - 2.4.4 - - 2.5.1 -script: bundle exec rspec -sudo: false diff --git a/README.md b/README.md index 9c8851f..4059082 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # Stater -[![Build Status](https://secure.travis-ci.org/infused/stater.png)](http://travis-ci.com/infused/stater) [![Gem Version](https://badge.fury.io/rb/stater.png)](http://badge.fury.io/rb/stater) -[![Code Climate](https://codeclimate.com/github/infused/stater.png)](https://codeclimate.com/github/infused/stater) A time value of money library Copyright (c) 2006-2018 Keith Morrison <keithm@infused.org>
infused/stater
6e117b106ecdc100459b99588d586f173749bb2e
migrate to travis-ci.com
diff --git a/README.md b/README.md index 9a3ca45..9c8851f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # Stater -[![Build Status](https://secure.travis-ci.org/infused/stater.png)](http://travis-ci.org/infused/stater) +[![Build Status](https://secure.travis-ci.org/infused/stater.png)](http://travis-ci.com/infused/stater) [![Gem Version](https://badge.fury.io/rb/stater.png)](http://badge.fury.io/rb/stater) [![Code Climate](https://codeclimate.com/github/infused/stater.png)](https://codeclimate.com/github/infused/stater) A time value of money library Copyright (c) 2006-2018 Keith Morrison <keithm@infused.org>
infused/stater
25999a3f23fb3659646873ece74260d144a5d59f
ruby version
diff --git a/.gitignore b/.gitignore index 83f6d39..262b419 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .rvmrc +.ruby-gemset +.ruby-version Gemfile.lock *.gem
infused/stater
24c519c0e3f2d5c6b2b56a8093156032afe63dd6
fraction expression solver
diff --git a/lib/stater.rb b/lib/stater.rb index 75533e5..2cd2743 100644 --- a/lib/stater.rb +++ b/lib/stater.rb @@ -1,6 +1,8 @@ require 'bigdecimal' require 'bigdecimal/util' require 'stater/tvm' require 'stater/base' require 'stater/amortization' + +require 'stater/fraction' diff --git a/lib/stater/fraction.rb b/lib/stater/fraction.rb new file mode 100644 index 0000000..3088e13 --- /dev/null +++ b/lib/stater/fraction.rb @@ -0,0 +1,11 @@ +module Stater + class FractionSolver + # solves expressions in the form of '2 1/2 + 3 3/5' + def solve(expression) + x, op, y = expression.split(/\ (\+|\-|\*|\/)\ /) + x = x.split(' ').sum {|n| n.strip.to_r } + y = y.split(' ').sum {|n| n.strip.to_r } + x.send(op.strip.to_sym, y) + end + end +end diff --git a/spec/unit/fraction_solver_spec.rb b/spec/unit/fraction_solver_spec.rb new file mode 100644 index 0000000..6f7eeb3 --- /dev/null +++ b/spec/unit/fraction_solver_spec.rb @@ -0,0 +1,10 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Stater::FractionSolver do + describe 'simplify' do + it 'works' do + solver = Stater::FractionSolver.new + expect(solver.solve('4 1/4 + 1 1/2')).to eq 23/4r + end + end +end
infused/stater
be1b15fa9bc1e499809fa21eaf2162c2d830cd7d
drop ruby-2.0.0 from testing
diff --git a/.travis.yml b/.travis.yml index a8f76a8..95f8d94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,12 @@ branches: only: - master language: ruby rvm: - - 2.0.0 - 2.1.10 - 2.2.6 - 2.3.3 - 2.4.0 - jruby-19mode script: bundle exec rspec sudo: false
infused/stater
fcb7e7de285d82d87401cc220ee59c07137f4303
remove old dependencies
diff --git a/stater.gemspec b/stater.gemspec index 0c3f7c9..1af0c89 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,28 +1,24 @@ lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] s.license = 'MIT' s.required_rubygems_version = '>= 1.8.0' - s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'nokogiri' - s.add_development_dependency 'autotest-standalone' - s.add_development_dependency 'autotest-growl' end -
infused/stater
dac2642da3e7f82941e20b3f1d01379fdf980928
specify license in gemfile
diff --git a/stater.gemspec b/stater.gemspec index 71414df..0c3f7c9 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,27 +1,28 @@ lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] + s.license = 'MIT' s.required_rubygems_version = '>= 1.8.0' s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'nokogiri' s.add_development_dependency 'autotest-standalone' s.add_development_dependency 'autotest-growl' end
infused/stater
9f0d0ece000b935ae432166f50d9c3342f46f0be
more spec cleanup
diff --git a/lib/stater/amortization.rb b/lib/stater/amortization.rb index 23c35cc..c506d97 100644 --- a/lib/stater/amortization.rb +++ b/lib/stater/amortization.rb @@ -1,45 +1,45 @@ Struct.new('Payment', :payment, :principal_paid, :interest_paid, :principal_balance) class NilClass def to_d nil end end module Stater class Amortization attr_accessor :principal attr_accessor :periodic_rate attr_accessor :periods - + def initialize(principal = nil, periodic_rate = nil, periods = nil) @schedule = [] @principal, @periodic_rate, @periods = principal.to_d, periodic_rate.to_d, periods end - + # Calculates the payment when given the principal amount and interest rate - def calculate_payment + def calculate_payment x = @periodic_rate * @principal * ((1 + @periodic_rate)**@periods) - y = ((1 + @periodic_rate)**@periods) - 1 + y = ((1 + @periodic_rate)**@periods) - 1 (x / y).round(2) end - + def schedule return [] unless @principal && @periodic_rate && @periods - + payment = calculate_payment principal_balance = @principal - + payments = [] 1.upto(@periods) do |payment_number| interest_paid = (principal_balance * @periodic_rate).round(2) principal_paid = payment - interest_paid principal_balance = principal_balance - principal_paid - + payments << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end payments end - + end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 13ccf0f..fcf8903 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,34 +1,34 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'rspec' require 'stater' require 'nokogiri' module CustomMatchers - def tvalue_schedule(xml_file) + def load_tvalue_schedule(xml_file) control_schedule = [] doc = Nokogiri(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) (doc/:amortizationline).each do |line| if (line/:amortizationlinetype).inner_text == '9' payment = extract_value(line, :payment1amount).to_d interest_paid = extract_value(line, :interestpaid).to_d principal_paid = extract_value(line, :principalpaid).to_d principal_balance = extract_value(line, :principalbalance).to_d control_schedule << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end end control_schedule end def extract_value(line, name) (line/name.to_sym).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') end end RSpec.configure do |config| config.include(CustomMatchers) end diff --git a/spec/unit/amortization_spec.rb b/spec/unit/amortization_spec.rb index 837887a..4a1c394 100644 --- a/spec/unit/amortization_spec.rb +++ b/spec/unit/amortization_spec.rb @@ -1,64 +1,63 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::Amortization do before do principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 @amortization = Stater::Amortization.new(principal, periodic_rate, periods) end it 'should correctly calculate the payment' do expect(@amortization.calculate_payment).to eq 2389.13 end it 'should return the calculated payment as a BigDecimal' do expect(@amortization.calculate_payment).to be_kind_of(BigDecimal) end it 'should convert principal to BigDecimal' do expect(@amortization.principal).to be_kind_of(BigDecimal) end it 'should convert periodic_rate to BigDecimal' do expect(@amortization.periodic_rate).to be_kind_of(BigDecimal) end describe 'when initialized with default parameters' do - before do - @amortization = Stater::Amortization.new - end + let(:amortization) { Stater::Amortization.new } - specify 'schedule should be an empty array' do - @amortization.schedule.should == [] + it 'is an empty array' do + expect(amortization.schedule).to eq [] end - specify 'principal should be nil' do - @amortization.principal.should be_nil + specify 'principal is nil' do + expect(amortization.principal).to be_nil end - specify 'periodic_rate should be nil' do - @amortization.periodic_rate.should be_nil + specify 'periodic_rate is nil' do + expect(amortization.periodic_rate).to be_nil end - specify 'periods should be nil' do - @amortization.periods.should be_nil + specify 'periods is nil' do + expect(amortization.periods).to be_nil end end describe 'schedule' do + let(:tvalue_schedule) { load_tvalue_schedule('FEC_example_3_3_1.xml') } + it 'should exactly match the TValue control schedule' do - @tvalue_schedule = tvalue_schedule('FEC_example_3_3_1.xml') - # @amortization.schedule.size.should == @tvalue_schedule.size - @amortization.schedule[0].should == @tvalue_schedule[0] - @amortization.schedule[1].should == @tvalue_schedule[1] - @amortization.schedule[25].should == @tvalue_schedule[25] - @amortization.schedule[70].should == @tvalue_schedule[70] - @amortization.schedule[150].should == @tvalue_schedule[150] - @amortization.schedule[179].should == @tvalue_schedule[179] - # @amortization.schedule[180].should == @tvalue_schedule[180] + # @amortization.schedule.size.should eq @tvalue_schedule.size + expect(@amortization.schedule[0]).to eq tvalue_schedule[0] + expect(@amortization.schedule[1]).to eq tvalue_schedule[1] + expect(@amortization.schedule[25]).to eq tvalue_schedule[25] + expect(@amortization.schedule[70]).to eq tvalue_schedule[70] + expect(@amortization.schedule[150]).to eq tvalue_schedule[150] + expect(@amortization.schedule[179]).to eq tvalue_schedule[179] + # @amortization.schedule[180].should eq @tvalue_schedule[180] end end end
infused/stater
83e464699f336c5f3d1fa2e84d157b296aad938d
remove FIXTURE_PATH
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0c802a6..13ccf0f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,36 +1,34 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'rspec' require 'stater' require 'nokogiri' -FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) - module CustomMatchers def tvalue_schedule(xml_file) control_schedule = [] doc = Nokogiri(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) (doc/:amortizationline).each do |line| if (line/:amortizationlinetype).inner_text == '9' payment = extract_value(line, :payment1amount).to_d interest_paid = extract_value(line, :interestpaid).to_d principal_paid = extract_value(line, :principalpaid).to_d principal_balance = extract_value(line, :principalbalance).to_d - + control_schedule << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end end - + control_schedule end - + def extract_value(line, name) (line/name.to_sym).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') end end RSpec.configure do |config| config.include(CustomMatchers) end
infused/stater
7785ddd60e4b2544ab0334b0d7055fe7fb602ea8
modernize specs
diff --git a/spec/unit/amortization_spec.rb b/spec/unit/amortization_spec.rb index 2be826f..837887a 100644 --- a/spec/unit/amortization_spec.rb +++ b/spec/unit/amortization_spec.rb @@ -1,64 +1,64 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::Amortization do before do principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 - + @amortization = Stater::Amortization.new(principal, periodic_rate, periods) end - + it 'should correctly calculate the payment' do - @amortization.calculate_payment.should == 2389.13 + expect(@amortization.calculate_payment).to eq 2389.13 end - + it 'should return the calculated payment as a BigDecimal' do - @amortization.calculate_payment.should be_kind_of(BigDecimal) + expect(@amortization.calculate_payment).to be_kind_of(BigDecimal) end - + it 'should convert principal to BigDecimal' do - @amortization.principal.should be_kind_of(BigDecimal) + expect(@amortization.principal).to be_kind_of(BigDecimal) end - + it 'should convert periodic_rate to BigDecimal' do - @amortization.periodic_rate.should be_kind_of(BigDecimal) + expect(@amortization.periodic_rate).to be_kind_of(BigDecimal) end describe 'when initialized with default parameters' do before do @amortization = Stater::Amortization.new end - + specify 'schedule should be an empty array' do @amortization.schedule.should == [] end - + specify 'principal should be nil' do @amortization.principal.should be_nil end - + specify 'periodic_rate should be nil' do @amortization.periodic_rate.should be_nil end - + specify 'periods should be nil' do @amortization.periods.should be_nil end end - + describe 'schedule' do it 'should exactly match the TValue control schedule' do @tvalue_schedule = tvalue_schedule('FEC_example_3_3_1.xml') # @amortization.schedule.size.should == @tvalue_schedule.size @amortization.schedule[0].should == @tvalue_schedule[0] @amortization.schedule[1].should == @tvalue_schedule[1] @amortization.schedule[25].should == @tvalue_schedule[25] @amortization.schedule[70].should == @tvalue_schedule[70] @amortization.schedule[150].should == @tvalue_schedule[150] @amortization.schedule[179].should == @tvalue_schedule[179] # @amortization.schedule[180].should == @tvalue_schedule[180] end end - + end diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb index d57dfe2..46891ee 100644 --- a/spec/unit/tvm_spec.rb +++ b/spec/unit/tvm_spec.rb @@ -1,68 +1,74 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::TVM do before do @present_value = 6000.00 @future_value = 7935.08 @interest = 0.04 @years = 7 @periods_per_year = 12 @delta = 0.005 end - + describe 'future_value' do - it "should calculate future value" do + it 'calculates future value' do fv = Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year) - fv.should be_within(@delta).of(@future_value) - end + expect(fv).to be_within(@delta).of(@future_value) + end + it "defaults to 12 periods per year" do fv = Stater::TVM.fv(@present_value, @interest, @years) expect(fv).to be_within(@delta).of(@future_value) end end - + describe 'present_value' do - it "should calculate present value" do - pv = Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year) - pv.should be_within(@delta).of(@present_value) + let(:pv) { Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year) } + + it 'calculates present value' do + expect(pv).to be_within(@delta).of(@present_value) end end describe 'interest' do - it "should calculate interest" do - interest = Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f - interest.should be_within(@delta).of(@interest) + let(:interest) { Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f } + + it 'calculates interest' do + expect(interest).to be_within(@delta).of(@interest) end end - + describe 'years' do - it "should caculate years" do - years = Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year) - years.should be_within(@delta).of(@years) + let(:years) { Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year) } + + it 'caculates years' do + expect(years).to be_within(@delta).of(@years) end end - + describe 'i_to_apr' do - it "should convert simple interest to APR" do - Stater::TVM.i_to_apr(0.18, 12).should be_within(@delta).of(0.195) + it 'should convert simple interest to APR' do + expect(Stater::TVM.i_to_apr(0.18, 12)).to be_within(@delta).of(0.195) end end - + describe 'apr_to_i' do - it "should convert APR to simple interest" do - Stater::TVM.apr_to_i(0.195, 12).should be_within(@delta).of(0.179) + it 'should convert APR to simple interest' do + expect(Stater::TVM.apr_to_i(0.195, 12)).to be_within(@delta).of(0.179) end end - + describe 'apr_to_ear' do - it "should convert APR to EAR" do - Stater::TVM.apr_to_ear(0.129, 12).should be_within(@delta).of(0.137) + it 'should convert APR to EAR' do + expect(Stater::TVM.apr_to_ear(0.129, 12)).to be_within(@delta).of(0.137) end end - + describe 'ear_to_apr' do - it "should convert EAR to APR" do - Stater::TVM.ear_to_apr(0.138, 12).should be_within(@delta).of(0.129) + let(:apr) { Stater::TVM.ear_to_apr(0.138, 12) } + + it 'should convert EAR to APR' do + expect(apr).to be_within(@delta).of(0.129) end end end
infused/stater
70990b4030e095faeadce375a7bec8cbf8d470eb
default fv periods_per_year to 12
diff --git a/lib/stater/tvm.rb b/lib/stater/tvm.rb index 77b1433..7388fdb 100644 --- a/lib/stater/tvm.rb +++ b/lib/stater/tvm.rb @@ -1,78 +1,78 @@ module Stater class TVM include Math class << self # Calculates the future value # pv = present value # i = simple interest rate # n = number of years # m = compounding periods per year - def fv(pv, i, n, m) + def fv(pv, i, n, m = 12) pv * (1 + (i/m)) ** (n*m) end # Calulates the present value # fv = future value # i = periodic interest rate # n = number of years # m = compounding periods per year def pv(fv, i, n, m) fv / (1 + (i/m)) ** (n*m) end # Calculates the nominal interest rate # pv = present value # fv = future value # y = years # n = compounding periods per year def i(pv, fv, y, n) n * ((fv / pv) ** (1 / (y.to_f * n)) - 1) end # Calculates the number of years # pv = present value # fv = future value # r = nominal interest rate # n = compounding periods per year def y(pv, fv, r, n) Math.log(fv / pv) / (n * Math.log(1 + (r / n))) end # Converts the nomical interest rate to APR (annual percentage rate) # r = nominal interest rate # n = compounding periods per year def i_to_apr(r, n) ((1 + (r / n)) ** n) - 1 end # Converts APR (annual percentage rate) to the nomical interest rate # apr = annual percentage rate # n = compounding periods per year def apr_to_i(apr, n) n * ((1 + apr) ** (1/n.to_f) - 1) end # Converts EAR (effective annual rate) to APR (annual percentage rate) # apr = annual percentage rate # n = compounding periods per year def apr_to_ear(apr, n) ((1 + apr / n)**n) - 1 end # Converts APR (annual percentage rate) to EAR (effective annual rate) # ear = effective annual rate # n = compounding periods per year def ear_to_apr(ear, n) n * ((1 + ear)**(1 / n.to_f) - 1) end alias_method :present_value, :pv alias_method :future_value, :fv alias_method :interest, :i alias_method :years, :y alias_method :annual_interest_to_apr, :i_to_apr alias_method :apr_to_annual_interest, :apr_to_i end end end \ No newline at end of file diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb index 89fd539..d57dfe2 100644 --- a/spec/unit/tvm_spec.rb +++ b/spec/unit/tvm_spec.rb @@ -1,64 +1,68 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::TVM do before do @present_value = 6000.00 @future_value = 7935.08 @interest = 0.04 @years = 7 @periods_per_year = 12 @delta = 0.005 end describe 'future_value' do it "should calculate future value" do fv = Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year) fv.should be_within(@delta).of(@future_value) end + it "defaults to 12 periods per year" do + fv = Stater::TVM.fv(@present_value, @interest, @years) + expect(fv).to be_within(@delta).of(@future_value) + end end describe 'present_value' do it "should calculate present value" do pv = Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year) pv.should be_within(@delta).of(@present_value) end end describe 'interest' do it "should calculate interest" do interest = Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f interest.should be_within(@delta).of(@interest) end end describe 'years' do it "should caculate years" do years = Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year) years.should be_within(@delta).of(@years) end end describe 'i_to_apr' do it "should convert simple interest to APR" do Stater::TVM.i_to_apr(0.18, 12).should be_within(@delta).of(0.195) end end describe 'apr_to_i' do it "should convert APR to simple interest" do Stater::TVM.apr_to_i(0.195, 12).should be_within(@delta).of(0.179) end end describe 'apr_to_ear' do it "should convert APR to EAR" do Stater::TVM.apr_to_ear(0.129, 12).should be_within(@delta).of(0.137) end end describe 'ear_to_apr' do it "should convert EAR to APR" do Stater::TVM.ear_to_apr(0.138, 12).should be_within(@delta).of(0.129) end end end
infused/stater
54cf021f4bba0cdab5f13ca59d795401d8695e49
ignore built gem files
diff --git a/.gitignore b/.gitignore index 456bd8f..83f6d39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .rvmrc Gemfile.lock +*.gem
infused/stater
2f379fe01c8cfc9e1c4d7df25eddbc2d80e717b6
fix spelling error
diff --git a/lib/stater/tvm.rb b/lib/stater/tvm.rb index 794f6a8..77b1433 100644 --- a/lib/stater/tvm.rb +++ b/lib/stater/tvm.rb @@ -1,78 +1,78 @@ module Stater class TVM include Math - + class << self # Calculates the future value # pv = present value # i = simple interest rate # n = number of years # m = compounding periods per year def fv(pv, i, n, m) pv * (1 + (i/m)) ** (n*m) end - + # Calulates the present value # fv = future value # i = periodic interest rate # n = number of years # m = compounding periods per year def pv(fv, i, n, m) fv / (1 + (i/m)) ** (n*m) end - - # Calculates the nomical interest rate + + # Calculates the nominal interest rate # pv = present value # fv = future value # y = years # n = compounding periods per year def i(pv, fv, y, n) n * ((fv / pv) ** (1 / (y.to_f * n)) - 1) end - + # Calculates the number of years # pv = present value # fv = future value # r = nominal interest rate # n = compounding periods per year def y(pv, fv, r, n) Math.log(fv / pv) / (n * Math.log(1 + (r / n))) end - + # Converts the nomical interest rate to APR (annual percentage rate) # r = nominal interest rate # n = compounding periods per year def i_to_apr(r, n) ((1 + (r / n)) ** n) - 1 end - + # Converts APR (annual percentage rate) to the nomical interest rate # apr = annual percentage rate # n = compounding periods per year def apr_to_i(apr, n) n * ((1 + apr) ** (1/n.to_f) - 1) end - + # Converts EAR (effective annual rate) to APR (annual percentage rate) # apr = annual percentage rate # n = compounding periods per year def apr_to_ear(apr, n) ((1 + apr / n)**n) - 1 end - + # Converts APR (annual percentage rate) to EAR (effective annual rate) # ear = effective annual rate # n = compounding periods per year def ear_to_apr(ear, n) n * ((1 + ear)**(1 / n.to_f) - 1) end - + alias_method :present_value, :pv alias_method :future_value, :fv alias_method :interest, :i alias_method :years, :y alias_method :annual_interest_to_apr, :i_to_apr alias_method :apr_to_annual_interest, :apr_to_i end end end \ No newline at end of file
infused/stater
7bb864cbd13d30e6ec0daff8a43291e82c95768c
dont lock to specific gem versions
diff --git a/stater.gemspec b/stater.gemspec index acb76f4..5d855fc 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,25 +1,25 @@ lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' - + s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] s.required_rubygems_version = '>= 1.8.0' - s.add_development_dependency 'rake', '~> 0.9.2' - s.add_development_dependency 'rspec', '~> 2.11.0' - s.add_development_dependency 'nokogiri', '~> 1.5.0' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec' + s.add_development_dependency 'nokogiri' end
infused/stater
36e158d511edd798a4252addd0ad654fdde2ffda
add code climate to readme
diff --git a/README.md b/README.md index ecf8f6d..99efa1a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # Stater [![Build Status](https://secure.travis-ci.org/infused/stater.png)](http://travis-ci.org/infused/stater) [![Gem Version](https://badge.fury.io/rb/stater.png)](http://badge.fury.io/rb/stater) +[![Code Climate](https://codeclimate.com/github/infused/stater.png)](https://codeclimate.com/github/infused/stater) + A time value of money library Copyright (c) 2006-2013 Keith Morrison <keithm@infused.org> \ No newline at end of file
infused/stater
3a7848901fc4527c5706feaabe93344981909f84
add gem version to readme
diff --git a/README.md b/README.md index 361402d..ecf8f6d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Stater [![Build Status](https://secure.travis-ci.org/infused/stater.png)](http://travis-ci.org/infused/stater) +[![Gem Version](https://badge.fury.io/rb/stater.png)](http://badge.fury.io/rb/stater) A time value of money library Copyright (c) 2006-2013 Keith Morrison <keithm@infused.org> \ No newline at end of file
infused/stater
40e193cd6e6b4d1b0320b9e17150028fc0c04662
add ruby-2.0.0 to travis-ci config
diff --git a/.travis.yml b/.travis.yml index ac5be92..b167a0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,14 @@ language: ruby rvm: + - 2.0.0 - 1.9.3 - 1.9.2 - 1.8.7 - ree - jruby-18mode - jruby-19mode - rbx-18mode - rbx-19mode branches: only: - master diff --git a/README.md b/README.md index a83340c..361402d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Stater +[![Build Status](https://secure.travis-ci.org/infused/stater.png)](http://travis-ci.org/infused/stater) A time value of money library -Copyright (c) 2006-2012 Keith Morrison <keithm@infused.org> \ No newline at end of file +Copyright (c) 2006-2013 Keith Morrison <keithm@infused.org> \ No newline at end of file
infused/stater
875002af04557b44339f879ef0940720a8a49b2d
fix Gemfile
diff --git a/Gemfile b/Gemfile index 7e083bb..56d5169 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,2 @@ gemspec -source :rubygems +source 'https://rubygems.org'
infused/stater
b4b283da9d4339aeb24e614d479375ba8dd5b9a9
remove encoding comments
diff --git a/lib/stater.rb b/lib/stater.rb index 96b85bb..75533e5 100644 --- a/lib/stater.rb +++ b/lib/stater.rb @@ -1,8 +1,6 @@ -# encoding: utf-8 - require 'bigdecimal' require 'bigdecimal/util' require 'stater/tvm' require 'stater/base' require 'stater/amortization' diff --git a/lib/stater/amortization.rb b/lib/stater/amortization.rb index f19ea86..23c35cc 100644 --- a/lib/stater/amortization.rb +++ b/lib/stater/amortization.rb @@ -1,47 +1,45 @@ -# encoding: utf-8 - Struct.new('Payment', :payment, :principal_paid, :interest_paid, :principal_balance) class NilClass def to_d nil end end module Stater class Amortization attr_accessor :principal attr_accessor :periodic_rate attr_accessor :periods def initialize(principal = nil, periodic_rate = nil, periods = nil) @schedule = [] @principal, @periodic_rate, @periods = principal.to_d, periodic_rate.to_d, periods end # Calculates the payment when given the principal amount and interest rate def calculate_payment x = @periodic_rate * @principal * ((1 + @periodic_rate)**@periods) y = ((1 + @periodic_rate)**@periods) - 1 (x / y).round(2) end def schedule return [] unless @principal && @periodic_rate && @periods payment = calculate_payment principal_balance = @principal payments = [] 1.upto(@periods) do |payment_number| interest_paid = (principal_balance * @periodic_rate).round(2) principal_paid = payment - interest_paid principal_balance = principal_balance - principal_paid payments << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end payments end end end \ No newline at end of file diff --git a/lib/stater/base.rb b/lib/stater/base.rb index 2d81569..264c7f8 100644 --- a/lib/stater/base.rb +++ b/lib/stater/base.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 - module Stater class Base class << self def sum_consecutive_integers(n) (n**2 + n) / 2 end end end end diff --git a/lib/stater/tvm.rb b/lib/stater/tvm.rb index 70da0dc..794f6a8 100644 --- a/lib/stater/tvm.rb +++ b/lib/stater/tvm.rb @@ -1,80 +1,78 @@ -# encoding: utf-8 - module Stater class TVM include Math class << self # Calculates the future value # pv = present value # i = simple interest rate # n = number of years # m = compounding periods per year def fv(pv, i, n, m) pv * (1 + (i/m)) ** (n*m) end # Calulates the present value # fv = future value # i = periodic interest rate # n = number of years # m = compounding periods per year def pv(fv, i, n, m) fv / (1 + (i/m)) ** (n*m) end # Calculates the nomical interest rate # pv = present value # fv = future value # y = years # n = compounding periods per year def i(pv, fv, y, n) n * ((fv / pv) ** (1 / (y.to_f * n)) - 1) end # Calculates the number of years # pv = present value # fv = future value # r = nominal interest rate # n = compounding periods per year def y(pv, fv, r, n) Math.log(fv / pv) / (n * Math.log(1 + (r / n))) end # Converts the nomical interest rate to APR (annual percentage rate) # r = nominal interest rate # n = compounding periods per year def i_to_apr(r, n) ((1 + (r / n)) ** n) - 1 end # Converts APR (annual percentage rate) to the nomical interest rate # apr = annual percentage rate # n = compounding periods per year def apr_to_i(apr, n) n * ((1 + apr) ** (1/n.to_f) - 1) end # Converts EAR (effective annual rate) to APR (annual percentage rate) # apr = annual percentage rate # n = compounding periods per year def apr_to_ear(apr, n) ((1 + apr / n)**n) - 1 end # Converts APR (annual percentage rate) to EAR (effective annual rate) # ear = effective annual rate # n = compounding periods per year def ear_to_apr(ear, n) n * ((1 + ear)**(1 / n.to_f) - 1) end alias_method :present_value, :pv alias_method :future_value, :fv alias_method :interest, :i alias_method :years, :y alias_method :annual_interest_to_apr, :i_to_apr alias_method :apr_to_annual_interest, :apr_to_i end end end \ No newline at end of file diff --git a/lib/stater/version.rb b/lib/stater/version.rb index 9d9b113..7e7ffcd 100644 --- a/lib/stater/version.rb +++ b/lib/stater/version.rb @@ -1,5 +1,3 @@ -# encoding: utf-8 - module Stater VERSION = '0.1.0' end \ No newline at end of file diff --git a/stater.gemspec b/stater.gemspec index ec73221..acb76f4 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,27 +1,25 @@ -# encoding: utf-8 - lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] s.required_rubygems_version = '>= 1.8.0' s.add_development_dependency 'rake', '~> 0.9.2' s.add_development_dependency 'rspec', '~> 2.11.0' s.add_development_dependency 'nokogiri', '~> 1.5.0' end
infused/stater
6faae0d3e73f96c1d93f32451801e26ac5eee7c5
shorten some spec lines
diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb index fa64010..89fd539 100644 --- a/spec/unit/tvm_spec.rb +++ b/spec/unit/tvm_spec.rb @@ -1,60 +1,64 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::TVM do before do @present_value = 6000.00 @future_value = 7935.08 @interest = 0.04 @years = 7 @periods_per_year = 12 @delta = 0.005 end describe 'future_value' do it "should calculate future value" do - Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@future_value) + fv = Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year) + fv.should be_within(@delta).of(@future_value) end end describe 'present_value' do it "should calculate present value" do - Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@present_value) + pv = Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year) + pv.should be_within(@delta).of(@present_value) end end describe 'interest' do it "should calculate interest" do - Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_within(@delta).of(@interest) + interest = Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f + interest.should be_within(@delta).of(@interest) end end describe 'years' do it "should caculate years" do - Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year).should be_within(@delta).of(@years) + years = Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year) + years.should be_within(@delta).of(@years) end end describe 'i_to_apr' do it "should convert simple interest to APR" do Stater::TVM.i_to_apr(0.18, 12).should be_within(@delta).of(0.195) end end describe 'apr_to_i' do it "should convert APR to simple interest" do Stater::TVM.apr_to_i(0.195, 12).should be_within(@delta).of(0.179) end end describe 'apr_to_ear' do it "should convert APR to EAR" do Stater::TVM.apr_to_ear(0.129, 12).should be_within(@delta).of(0.137) end end describe 'ear_to_apr' do it "should convert EAR to APR" do Stater::TVM.ear_to_apr(0.138, 12).should be_within(@delta).of(0.129) end end end
infused/stater
1be54fd2e28896297f9a45a486f4e966660fd2b5
extract extract_value method
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 877783a..0c802a6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,30 +1,36 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'rspec' require 'stater' require 'nokogiri' FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) module CustomMatchers def tvalue_schedule(xml_file) control_schedule = [] doc = Nokogiri(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) (doc/:amortizationline).each do |line| if (line/:amortizationlinetype).inner_text == '9' - payment = (line/:payment1amount).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - interest_paid = (line/:interestpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - principal_paid = (line/:principalpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - principal_balance = (line/:principalbalance).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - control_schedule << Struct::Payment.new(payment.to_d, principal_paid.to_d, interest_paid.to_d, principal_balance.to_d) + payment = extract_value(line, :payment1amount).to_d + interest_paid = extract_value(line, :interestpaid).to_d + principal_paid = extract_value(line, :principalpaid).to_d + principal_balance = extract_value(line, :principalbalance).to_d + + control_schedule << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end end + control_schedule end + + def extract_value(line, name) + (line/name.to_sym).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + end end RSpec.configure do |config| config.include(CustomMatchers) end
infused/stater
a2bfcd1fb32288ded864b5715a6dc7fca04c772e
bump required rubygems and rspec versions
diff --git a/Rakefile b/Rakefile index 8b590a9..6d9acd2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,21 +1,19 @@ -# encoding: utf-8 - require 'rubygems' require 'bundler/setup'; Bundler.setup(:default, :development) require 'rspec/core/rake_task' RSpec::Core::RakeTask.new :spec do |t| t.rspec_opts = %w(--color) end RSpec::Core::RakeTask.new :specdoc do |t| t.rspec_opts = %w(-fl) end task :default => :spec desc "Open an irb session preloaded with this library" task :console do sh "irb -rubygems -I lib -r stater.rb" end \ No newline at end of file diff --git a/stater.gemspec b/stater.gemspec index 69fe104..ec73221 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,27 +1,27 @@ # encoding: utf-8 lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] - s.required_rubygems_version = '>= 1.3.0' + s.required_rubygems_version = '>= 1.8.0' s.add_development_dependency 'rake', '~> 0.9.2' - s.add_development_dependency 'rspec', '~> 2.8.0' + s.add_development_dependency 'rspec', '~> 2.11.0' s.add_development_dependency 'nokogiri', '~> 1.5.0' end
infused/stater
b12e1683ef22dee5530de53cd91832135f66bfd9
add travis-ci config file
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ac5be92 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +language: ruby +rvm: + - 1.9.3 + - 1.9.2 + - 1.8.7 + - ree + - jruby-18mode + - jruby-19mode + - rbx-18mode + - rbx-19mode +branches: + only: + - master
infused/stater
0f652d092b8f678b169e58d614338424765aa242
setup bundler
diff --git a/Rakefile b/Rakefile index e551dc6..8b590a9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,21 @@ # encoding: utf-8 require 'rubygems' +require 'bundler/setup'; +Bundler.setup(:default, :development) require 'rspec/core/rake_task' RSpec::Core::RakeTask.new :spec do |t| - t.rspec_opts = %w(-fs --color) + t.rspec_opts = %w(--color) end -task :default => :spec \ No newline at end of file +RSpec::Core::RakeTask.new :specdoc do |t| + t.rspec_opts = %w(-fl) +end + +task :default => :spec + +desc "Open an irb session preloaded with this library" +task :console do + sh "irb -rubygems -I lib -r stater.rb" +end \ No newline at end of file diff --git a/lib/stater/amortization.rb b/lib/stater/amortization.rb index 375f385..f19ea86 100644 --- a/lib/stater/amortization.rb +++ b/lib/stater/amortization.rb @@ -1,52 +1,47 @@ # encoding: utf-8 Struct.new('Payment', :payment, :principal_paid, :interest_paid, :principal_balance) class NilClass def to_d nil end end -# TODO: test that this actually works -# BigDecimal.mode(BigDecimal::ROUND_HALF_EVEN) - module Stater class Amortization - attr_accessor :principal attr_accessor :periodic_rate attr_accessor :periods def initialize(principal = nil, periodic_rate = nil, periods = nil) @schedule = [] @principal, @periodic_rate, @periods = principal.to_d, periodic_rate.to_d, periods end # Calculates the payment when given the principal amount and interest rate def calculate_payment x = @periodic_rate * @principal * ((1 + @periodic_rate)**@periods) y = ((1 + @periodic_rate)**@periods) - 1 (x / y).round(2) end def schedule - return [] if @principal.nil? or @periodic_rate.nil? or @periods.nil? + return [] unless @principal && @periodic_rate && @periods - payments = [] payment = calculate_payment principal_balance = @principal - + + payments = [] 1.upto(@periods) do |payment_number| interest_paid = (principal_balance * @periodic_rate).round(2) principal_paid = payment - interest_paid principal_balance = principal_balance - principal_paid payments << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end - payments end end end \ No newline at end of file diff --git a/stater.gemspec b/stater.gemspec index 21f0acd..69fe104 100644 --- a/stater.gemspec +++ b/stater.gemspec @@ -1,26 +1,27 @@ # encoding: utf-8 lib = File.expand_path('../lib/', __FILE__) $:.unshift lib unless $:.include?(lib) require 'stater/version' Gem::Specification.new do |s| s.name = 'stater' s.version = Stater::VERSION s.authors = ['Keith Morrison'] s.email = 'keithm@infused.org' s.homepage = 'http://github.com/infused/stater' s.summary = 'Time Value of Money calulations' s.description = 'Time Value of Money calulations' s.rdoc_options = ['--charset=UTF-8'] s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] s.test_files = Dir.glob('spec/**/*_spec.rb') s.require_paths = ['lib'] s.required_rubygems_version = '>= 1.3.0' - s.add_development_dependency 'rspec', '2.5.0' - s.add_development_dependency 'hpricot', '0.8.4' + s.add_development_dependency 'rake', '~> 0.9.2' + s.add_development_dependency 'rspec', '~> 2.8.0' + s.add_development_dependency 'nokogiri', '~> 1.5.0' end
infused/stater
69789aab27aa05b8b2a018788dd7ae4b38c848bf
Cleanup tvalue_schedule matcher
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0e66bd6..877783a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,32 +1,30 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'rspec' require 'stater' require 'nokogiri' FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) module CustomMatchers def tvalue_schedule(xml_file) control_schedule = [] doc = Nokogiri(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) - lines = (doc/:tvalueamortizationschedule/:amortizationline) - lines.each do |line| - if line.search(:amortizationlinetype).inner_text == '9' - payment = line.search(:payment1amount).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - interest_paid = line.search(:interestpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - principal_paid = line.search(:principalpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - principal_balance = line.search(:principalbalance).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - + (doc/:amortizationline).each do |line| + if (line/:amortizationlinetype).inner_text == '9' + payment = (line/:payment1amount).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + interest_paid = (line/:interestpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + principal_paid = (line/:principalpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + principal_balance = (line/:principalbalance).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') control_schedule << Struct::Payment.new(payment.to_d, principal_paid.to_d, interest_paid.to_d, principal_balance.to_d) end end control_schedule end end RSpec.configure do |config| config.include(CustomMatchers) end
infused/stater
898dbec881ce2d2834c73dd2c10b903539a65e2a
Refactor tvm specs
diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb index ceb164a..fa64010 100644 --- a/spec/unit/tvm_spec.rb +++ b/spec/unit/tvm_spec.rb @@ -1,44 +1,60 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::TVM do before do @present_value = 6000.00 @future_value = 7935.08 @interest = 0.04 @years = 7 @periods_per_year = 12 @delta = 0.005 end - it "should calculate present value" do - Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@present_value) - end - - it "should calculate future value" do - Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@future_value) + describe 'future_value' do + it "should calculate future value" do + Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@future_value) + end end - it "should calculate interest" do - Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_within(@delta).of(@interest) + describe 'present_value' do + it "should calculate present value" do + Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@present_value) + end + end + + describe 'interest' do + it "should calculate interest" do + Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_within(@delta).of(@interest) + end end - it "should caculate years" do - Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year).should be_within(@delta).of(@years) + describe 'years' do + it "should caculate years" do + Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year).should be_within(@delta).of(@years) + end end - it "should convert simple interest to APR" do - Stater::TVM.i_to_apr(0.18, 12).should be_within(@delta).of(0.195) + describe 'i_to_apr' do + it "should convert simple interest to APR" do + Stater::TVM.i_to_apr(0.18, 12).should be_within(@delta).of(0.195) + end end - it "should convert APR to simple interest" do - Stater::TVM.apr_to_i(0.195, 12).should be_within(@delta).of(0.179) + describe 'apr_to_i' do + it "should convert APR to simple interest" do + Stater::TVM.apr_to_i(0.195, 12).should be_within(@delta).of(0.179) + end end - it "should convert APR to EAR" do - Stater::TVM.apr_to_ear(0.129, 12).should be_within(@delta).of(0.137) + describe 'apr_to_ear' do + it "should convert APR to EAR" do + Stater::TVM.apr_to_ear(0.129, 12).should be_within(@delta).of(0.137) + end end - it "should convert EAR to APR" do - Stater::TVM.ear_to_apr(0.138, 12).should be_within(@delta).of(0.129) + describe 'ear_to_apr' do + it "should convert EAR to APR" do + Stater::TVM.ear_to_apr(0.138, 12).should be_within(@delta).of(0.129) + end end end
infused/stater
fff92a0677af52051d05173c3a8aff00a0abece4
tvalue comparison test
diff --git a/lib/stater/amortization.rb b/lib/stater/amortization.rb index ce8b607..375f385 100644 --- a/lib/stater/amortization.rb +++ b/lib/stater/amortization.rb @@ -1,51 +1,52 @@ # encoding: utf-8 -Struct.new('Payment', :number, :payment, :principal_paid, :interest_paid, :principal_balance) +Struct.new('Payment', :payment, :principal_paid, :interest_paid, :principal_balance) class NilClass def to_d nil end end # TODO: test that this actually works # BigDecimal.mode(BigDecimal::ROUND_HALF_EVEN) module Stater class Amortization attr_accessor :principal attr_accessor :periodic_rate attr_accessor :periods def initialize(principal = nil, periodic_rate = nil, periods = nil) @schedule = [] @principal, @periodic_rate, @periods = principal.to_d, periodic_rate.to_d, periods end # Calculates the payment when given the principal amount and interest rate def calculate_payment x = @periodic_rate * @principal * ((1 + @periodic_rate)**@periods) y = ((1 + @periodic_rate)**@periods) - 1 (x / y).round(2) end def schedule return [] if @principal.nil? or @periodic_rate.nil? or @periods.nil? payments = [] payment = calculate_payment principal_balance = @principal 1.upto(@periods) do |payment_number| interest_paid = (principal_balance * @periodic_rate).round(2) principal_paid = payment - interest_paid principal_balance = principal_balance - principal_paid - payments << Struct::Payment.new(payment_number, payment, principal_paid, interest_paid, principal_balance) + payments << Struct::Payment.new(payment, principal_paid, interest_paid, principal_balance) end + payments end end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0403754..0e66bd6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,32 +1,32 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'rspec' require 'stater' -require 'hpricot' +require 'nokogiri' FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) module CustomMatchers def tvalue_schedule(xml_file) control_schedule = [] - doc = Hpricot(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) + doc = Nokogiri(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) lines = (doc/:tvalueamortizationschedule/:amortizationline) lines.each do |line| - if line.search(:amortizationlinetype).innerHTML == '9' - payment = line.search(:payment1amount).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') - interest_paid = line.search(:interestpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') - principal_paid = line.search(:principalpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') - principal_balance = line.search(:principalbalance).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + if line.search(:amortizationlinetype).inner_text == '9' + payment = line.search(:payment1amount).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + interest_paid = line.search(:interestpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + principal_paid = line.search(:principalpaid).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') + principal_balance = line.search(:principalbalance).inner_text.gsub(/(\d{2})\d{2}$/, '.\1') - control_schedule << Struct::Payment.new(nil, payment, principal_paid, interest_paid, principal_balance) + control_schedule << Struct::Payment.new(payment.to_d, principal_paid.to_d, interest_paid.to_d, principal_balance.to_d) end end control_schedule end end RSpec.configure do |config| config.include(CustomMatchers) end diff --git a/spec/unit/amortization_spec.rb b/spec/unit/amortization_spec.rb index 9a4b405..2be826f 100644 --- a/spec/unit/amortization_spec.rb +++ b/spec/unit/amortization_spec.rb @@ -1,57 +1,64 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::Amortization do before do principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 @amortization = Stater::Amortization.new(principal, periodic_rate, periods) end it 'should correctly calculate the payment' do @amortization.calculate_payment.should == 2389.13 end it 'should return the calculated payment as a BigDecimal' do @amortization.calculate_payment.should be_kind_of(BigDecimal) end it 'should convert principal to BigDecimal' do @amortization.principal.should be_kind_of(BigDecimal) end it 'should convert periodic_rate to BigDecimal' do @amortization.periodic_rate.should be_kind_of(BigDecimal) end describe 'when initialized with default parameters' do before do @amortization = Stater::Amortization.new end specify 'schedule should be an empty array' do @amortization.schedule.should == [] end specify 'principal should be nil' do @amortization.principal.should be_nil end specify 'periodic_rate should be nil' do @amortization.periodic_rate.should be_nil end specify 'periods should be nil' do @amortization.periods.should be_nil end end + describe 'schedule' do + it 'should exactly match the TValue control schedule' do + @tvalue_schedule = tvalue_schedule('FEC_example_3_3_1.xml') + # @amortization.schedule.size.should == @tvalue_schedule.size + @amortization.schedule[0].should == @tvalue_schedule[0] + @amortization.schedule[1].should == @tvalue_schedule[1] + @amortization.schedule[25].should == @tvalue_schedule[25] + @amortization.schedule[70].should == @tvalue_schedule[70] + @amortization.schedule[150].should == @tvalue_schedule[150] + @amortization.schedule[179].should == @tvalue_schedule[179] + # @amortization.schedule[180].should == @tvalue_schedule[180] + end + end + end - -describe Stater::Amortization, 'schedule' do - it 'should exactly match the TValue control schedule' - # it 'should exactly match the TValue control schedule' do - # @amortization.schedule.size.should == tvalue_schedule('FEC_example_3_3_1.xml').size - # end -end \ No newline at end of file
infused/stater
e51ee09a8e65905e03dcdfb63ea9761271c3b0a3
autotest file mappings
diff --git a/.autotest b/.autotest new file mode 100644 index 0000000..32e70c3 --- /dev/null +++ b/.autotest @@ -0,0 +1,16 @@ +Autotest.add_hook :initialize do |autotest| + autotest.clear_mappings + + autotest.add_mapping(%r%^lib/stater/(.*)\.rb$%) do |filename, m| + autotest.files_matching %r!spec/(unit|functional)/#{m[1]}_spec.rb! + end + + autotest.add_mapping(%r%^spec/(unit|functional)/.*\.rb$%) do |filename, m| + filename + end + + %w{.svn .hg .git .dbf .dbt .fpt .txt bin Rakefile .gemspec .autotest}.each do |exception| + autotest.add_exception(exception) + end +end +
infused/stater
54864ba2d04beeb55f5060f6227bfa4b47a9d416
Refactor amortization tests
diff --git a/lib/stater/amortization.rb b/lib/stater/amortization.rb index eab82dd..ce8b607 100644 --- a/lib/stater/amortization.rb +++ b/lib/stater/amortization.rb @@ -1,54 +1,51 @@ # encoding: utf-8 Struct.new('Payment', :number, :payment, :principal_paid, :interest_paid, :principal_balance) class NilClass def to_d nil end end # TODO: test that this actually works # BigDecimal.mode(BigDecimal::ROUND_HALF_EVEN) module Stater class Amortization attr_accessor :principal attr_accessor :periodic_rate attr_accessor :periods def initialize(principal = nil, periodic_rate = nil, periods = nil) @schedule = [] @principal, @periodic_rate, @periods = principal.to_d, periodic_rate.to_d, periods end # Calculates the payment when given the principal amount and interest rate - def calculate_payment(periodic_rate = @periodic_rate, periods = @periods) - raise ArgumentError, "periodic_rate should be a BigDecimal" unless periodic_rate.is_a?(BigDecimal) - raise ArgumentError, "periods should be a Fixnum" unless periods.is_a?(Fixnum) - - x = periodic_rate * principal * ((1 + periodic_rate)**periods) - y = ((1 + periodic_rate)**periods) - 1 + def calculate_payment + x = @periodic_rate * @principal * ((1 + @periodic_rate)**@periods) + y = ((1 + @periodic_rate)**@periods) - 1 (x / y).round(2) end def schedule return [] if @principal.nil? or @periodic_rate.nil? or @periods.nil? payments = [] payment = calculate_payment principal_balance = @principal 1.upto(@periods) do |payment_number| interest_paid = (principal_balance * @periodic_rate).round(2) principal_paid = payment - interest_paid principal_balance = principal_balance - principal_paid payments << Struct::Payment.new(payment_number, payment, principal_paid, interest_paid, principal_balance) end payments end end end \ No newline at end of file diff --git a/spec/unit/amortization_spec.rb b/spec/unit/amortization_spec.rb index 10ce4e3..9a4b405 100644 --- a/spec/unit/amortization_spec.rb +++ b/spec/unit/amortization_spec.rb @@ -1,66 +1,57 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe Stater::Amortization, 'when initialized' do - - before do - @amortization = Stater::Amortization.new - end - - specify 'schedule should be an empty array' do - @amortization.schedule.should == [] - end - - specify 'principal should be nil' do - @amortization.principal.should be_nil - end - - specify 'periodic_rate should be nil' do - @amortization.periodic_rate.should be_nil - end - - specify 'periods should be nil' do - @amortization.periods.should be_nil - end - -end - describe Stater::Amortization do before do principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 @amortization = Stater::Amortization.new(principal, periodic_rate, periods) end - it 'should correctly calculate a payment when given the principal, periodic_rate, and periods' do + it 'should correctly calculate the payment' do @amortization.calculate_payment.should == 2389.13 end it 'should return the calculated payment as a BigDecimal' do @amortization.calculate_payment.should be_kind_of(BigDecimal) end it 'should convert principal to BigDecimal' do @amortization.principal.should be_kind_of(BigDecimal) end it 'should convert periodic_rate to BigDecimal' do @amortization.periodic_rate.should be_kind_of(BigDecimal) end -end -describe Stater::Amortization, 'schedule' do - before do - principal = 250000.00 - periodic_rate = 0.08 / 12 - periods = 15 * 12 + describe 'when initialized with default parameters' do + before do + @amortization = Stater::Amortization.new + end - @amortization = Stater::Amortization.new(principal, periodic_rate, periods) + specify 'schedule should be an empty array' do + @amortization.schedule.should == [] + end + + specify 'principal should be nil' do + @amortization.principal.should be_nil + end + + specify 'periodic_rate should be nil' do + @amortization.periodic_rate.should be_nil + end + + specify 'periods should be nil' do + @amortization.periods.should be_nil + end end +end + +describe Stater::Amortization, 'schedule' do it 'should exactly match the TValue control schedule' # it 'should exactly match the TValue control schedule' do # @amortization.schedule.size.should == tvalue_schedule('FEC_example_3_3_1.xml').size # end end \ No newline at end of file
infused/stater
ac60de91919b5006c06031aefe85a289b2fa3425
Add MIT license
diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..dcb225f --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2007-2011 Keith Morrison <keithm@infused.org> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.txt b/README.txt index 6cd2306..e76e103 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,5 @@ == Stater -A time value of money library \ No newline at end of file +A time value of money library + +Copyright (c) 2006-2011 Keith Morrison <keithm@infused.org> \ No newline at end of file
infused/stater
a43ecb640eed83b63cad0fdc5b0f8c110177e83b
Setup gemspec and upgrade to RSpec2
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..456bd8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.rvmrc +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7e083bb --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +gemspec +source :rubygems diff --git a/Manifest.txt b/Manifest.txt deleted file mode 100644 index e69de29..0000000 diff --git a/Rakefile b/Rakefile index 28b8efe..e551dc6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,20 +1,10 @@ -require 'rubygems' -require 'hoe' -require 'spec/rake/spectask' +# encoding: utf-8 -Hoe.new('stater', '1.0.0') do |p| - p.author = 'Keith Morrison' - p.email = 'keithm@infused.org' - p.test_globs = ['test/**/*_test.rb'] -end +require 'rubygems' -desc 'Run specs' -Spec::Rake::SpecTask.new :spec do |t| - t.spec_files = FileList['spec/**/*spec.rb'] +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new :spec do |t| + t.rspec_opts = %w(-fs --color) end -desc 'Run spec docs' -Spec::Rake::SpecTask.new :specdoc do |t| - t.spec_opts = ['-f specdoc'] - t.spec_files = FileList['spec/**/*spec.rb'] -end +task :default => :spec \ No newline at end of file diff --git a/lib/stater.rb b/lib/stater.rb index 75533e5..96b85bb 100644 --- a/lib/stater.rb +++ b/lib/stater.rb @@ -1,6 +1,8 @@ +# encoding: utf-8 + require 'bigdecimal' require 'bigdecimal/util' require 'stater/tvm' require 'stater/base' require 'stater/amortization' diff --git a/lib/stater/amortization.rb b/lib/stater/amortization.rb index 1d840e3..eab82dd 100644 --- a/lib/stater/amortization.rb +++ b/lib/stater/amortization.rb @@ -1,52 +1,54 @@ +# encoding: utf-8 + Struct.new('Payment', :number, :payment, :principal_paid, :interest_paid, :principal_balance) class NilClass def to_d nil end end # TODO: test that this actually works # BigDecimal.mode(BigDecimal::ROUND_HALF_EVEN) module Stater class Amortization attr_accessor :principal attr_accessor :periodic_rate attr_accessor :periods def initialize(principal = nil, periodic_rate = nil, periods = nil) @schedule = [] @principal, @periodic_rate, @periods = principal.to_d, periodic_rate.to_d, periods end # Calculates the payment when given the principal amount and interest rate def calculate_payment(periodic_rate = @periodic_rate, periods = @periods) raise ArgumentError, "periodic_rate should be a BigDecimal" unless periodic_rate.is_a?(BigDecimal) raise ArgumentError, "periods should be a Fixnum" unless periods.is_a?(Fixnum) x = periodic_rate * principal * ((1 + periodic_rate)**periods) y = ((1 + periodic_rate)**periods) - 1 (x / y).round(2) end def schedule return [] if @principal.nil? or @periodic_rate.nil? or @periods.nil? payments = [] payment = calculate_payment principal_balance = @principal 1.upto(@periods) do |payment_number| interest_paid = (principal_balance * @periodic_rate).round(2) principal_paid = payment - interest_paid principal_balance = principal_balance - principal_paid payments << Struct::Payment.new(payment_number, payment, principal_paid, interest_paid, principal_balance) end payments end end end \ No newline at end of file diff --git a/lib/stater/base.rb b/lib/stater/base.rb index 264c7f8..2d81569 100644 --- a/lib/stater/base.rb +++ b/lib/stater/base.rb @@ -1,9 +1,11 @@ +# encoding: utf-8 + module Stater class Base class << self def sum_consecutive_integers(n) (n**2 + n) / 2 end end end end diff --git a/lib/stater/tvm.rb b/lib/stater/tvm.rb index 794f6a8..70da0dc 100644 --- a/lib/stater/tvm.rb +++ b/lib/stater/tvm.rb @@ -1,78 +1,80 @@ +# encoding: utf-8 + module Stater class TVM include Math class << self # Calculates the future value # pv = present value # i = simple interest rate # n = number of years # m = compounding periods per year def fv(pv, i, n, m) pv * (1 + (i/m)) ** (n*m) end # Calulates the present value # fv = future value # i = periodic interest rate # n = number of years # m = compounding periods per year def pv(fv, i, n, m) fv / (1 + (i/m)) ** (n*m) end # Calculates the nomical interest rate # pv = present value # fv = future value # y = years # n = compounding periods per year def i(pv, fv, y, n) n * ((fv / pv) ** (1 / (y.to_f * n)) - 1) end # Calculates the number of years # pv = present value # fv = future value # r = nominal interest rate # n = compounding periods per year def y(pv, fv, r, n) Math.log(fv / pv) / (n * Math.log(1 + (r / n))) end # Converts the nomical interest rate to APR (annual percentage rate) # r = nominal interest rate # n = compounding periods per year def i_to_apr(r, n) ((1 + (r / n)) ** n) - 1 end # Converts APR (annual percentage rate) to the nomical interest rate # apr = annual percentage rate # n = compounding periods per year def apr_to_i(apr, n) n * ((1 + apr) ** (1/n.to_f) - 1) end # Converts EAR (effective annual rate) to APR (annual percentage rate) # apr = annual percentage rate # n = compounding periods per year def apr_to_ear(apr, n) ((1 + apr / n)**n) - 1 end # Converts APR (annual percentage rate) to EAR (effective annual rate) # ear = effective annual rate # n = compounding periods per year def ear_to_apr(ear, n) n * ((1 + ear)**(1 / n.to_f) - 1) end alias_method :present_value, :pv alias_method :future_value, :fv alias_method :interest, :i alias_method :years, :y alias_method :annual_interest_to_apr, :i_to_apr alias_method :apr_to_annual_interest, :apr_to_i end end end \ No newline at end of file diff --git a/lib/stater/version.rb b/lib/stater/version.rb new file mode 100644 index 0000000..9d9b113 --- /dev/null +++ b/lib/stater/version.rb @@ -0,0 +1,5 @@ +# encoding: utf-8 + +module Stater + VERSION = '0.1.0' +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 63c8bc1..0403754 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,33 +1,32 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' -require 'spec' +require 'rspec' require 'stater' require 'hpricot' FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) module CustomMatchers def tvalue_schedule(xml_file) control_schedule = [] doc = Hpricot(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) lines = (doc/:tvalueamortizationschedule/:amortizationline) lines.each do |line| if line.search(:amortizationlinetype).innerHTML == '9' payment = line.search(:payment1amount).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') interest_paid = line.search(:interestpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') principal_paid = line.search(:principalpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') principal_balance = line.search(:principalbalance).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') control_schedule << Struct::Payment.new(nil, payment, principal_paid, interest_paid, principal_balance) end end control_schedule end end -Spec::Runner.configure do |config| +RSpec.configure do |config| config.include(CustomMatchers) - config.mock_with :mocha end diff --git a/spec/unit/amortization_spec.rb b/spec/unit/amortization_spec.rb index d7417ae..10ce4e3 100644 --- a/spec/unit/amortization_spec.rb +++ b/spec/unit/amortization_spec.rb @@ -1,66 +1,66 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::Amortization, 'when initialized' do - before(:each) do + before do @amortization = Stater::Amortization.new end specify 'schedule should be an empty array' do @amortization.schedule.should == [] end specify 'principal should be nil' do @amortization.principal.should be_nil end specify 'periodic_rate should be nil' do @amortization.periodic_rate.should be_nil end specify 'periods should be nil' do @amortization.periods.should be_nil end end describe Stater::Amortization do - before(:each) do + before do principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 @amortization = Stater::Amortization.new(principal, periodic_rate, periods) end it 'should correctly calculate a payment when given the principal, periodic_rate, and periods' do @amortization.calculate_payment.should == 2389.13 end it 'should return the calculated payment as a BigDecimal' do @amortization.calculate_payment.should be_kind_of(BigDecimal) end it 'should convert principal to BigDecimal' do @amortization.principal.should be_kind_of(BigDecimal) end it 'should convert periodic_rate to BigDecimal' do @amortization.periodic_rate.should be_kind_of(BigDecimal) end end describe Stater::Amortization, 'schedule' do - before(:each) do + before do principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 @amortization = Stater::Amortization.new(principal, periodic_rate, periods) end it 'should exactly match the TValue control schedule' # it 'should exactly match the TValue control schedule' do # @amortization.schedule.size.should == tvalue_schedule('FEC_example_3_3_1.xml').size # end end \ No newline at end of file diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb index cca9faa..ceb164a 100644 --- a/spec/unit/tvm_spec.rb +++ b/spec/unit/tvm_spec.rb @@ -1,44 +1,44 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::TVM do - before(:each) do + before do @present_value = 6000.00 @future_value = 7935.08 @interest = 0.04 @years = 7 @periods_per_year = 12 @delta = 0.005 end it "should calculate present value" do - Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_close(@present_value, @delta) + Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@present_value) end it "should calculate future value" do - Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_close(@future_value, @delta) + Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_within(@delta).of(@future_value) end it "should calculate interest" do - Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_close(@interest, @delta) + Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_within(@delta).of(@interest) end it "should caculate years" do - Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year).should be_close(@years, @delta) + Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year).should be_within(@delta).of(@years) end it "should convert simple interest to APR" do - Stater::TVM.i_to_apr(0.18, 12).should be_close(0.195, @delta) + Stater::TVM.i_to_apr(0.18, 12).should be_within(@delta).of(0.195) end it "should convert APR to simple interest" do - Stater::TVM.apr_to_i(0.195, 12).should be_close(0.179, @delta) + Stater::TVM.apr_to_i(0.195, 12).should be_within(@delta).of(0.179) end it "should convert APR to EAR" do - Stater::TVM.apr_to_ear(0.129, 12).should be_close(0.137, @delta) + Stater::TVM.apr_to_ear(0.129, 12).should be_within(@delta).of(0.137) end it "should convert EAR to APR" do - Stater::TVM.ear_to_apr(0.138, 12).should be_close(0.129, @delta) + Stater::TVM.ear_to_apr(0.138, 12).should be_within(@delta).of(0.129) end end diff --git a/stater.gemspec b/stater.gemspec new file mode 100644 index 0000000..21f0acd --- /dev/null +++ b/stater.gemspec @@ -0,0 +1,26 @@ +# encoding: utf-8 + +lib = File.expand_path('../lib/', __FILE__) +$:.unshift lib unless $:.include?(lib) +require 'stater/version' + +Gem::Specification.new do |s| + s.name = 'stater' + s.version = Stater::VERSION + s.authors = ['Keith Morrison'] + s.email = 'keithm@infused.org' + s.homepage = 'http://github.com/infused/stater' + s.summary = 'Time Value of Money calulations' + s.description = 'Time Value of Money calulations' + + s.rdoc_options = ['--charset=UTF-8'] + s.extra_rdoc_files = ['README.md', 'MIT-LICENSE'] + s.files = Dir['[A-Z]*', '{doc,lib,spec}/**/*'] + s.test_files = Dir.glob('spec/**/*_spec.rb') + s.require_paths = ['lib'] + + s.required_rubygems_version = '>= 1.3.0' + s.add_development_dependency 'rspec', '2.5.0' + s.add_development_dependency 'hpricot', '0.8.4' +end +
infused/stater
788b6b0a3df2fdf0333d2789badd26fc7476ff61
Finish up rspec
diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..6cd2306 --- /dev/null +++ b/README.txt @@ -0,0 +1,3 @@ +== Stater + +A time value of money library \ No newline at end of file diff --git a/doc/tvalue/amortization_xml.txt b/doc/tvalue/amortization_xml.txt new file mode 100644 index 0000000..63df9b0 --- /dev/null +++ b/doc/tvalue/amortization_xml.txt @@ -0,0 +1,2 @@ +AmortizationLineType 8 = Loan +AmortizationLineType 9 = Payment \ No newline at end of file diff --git a/spec/fixtures/tvalue_schedules/FEC_example_3_3_1.xml b/spec/fixtures/tvalue_schedules/FEC_example_3_3_1.xml new file mode 100644 index 0000000..e8827e9 --- /dev/null +++ b/spec/fixtures/tvalue_schedules/FEC_example_3_3_1.xml @@ -0,0 +1,3593 @@ +<?xml version='1.0' encoding='windows-1252'?> +<TValueAmortizationSchedule> + <Rounding>0</Rounding> + <Compounding>6</Compounding> + <NominalAnnualRate>0.08</NominalAnnualRate> + <APR>0.08</APR> + <FinanceCharge>1800435100</FinanceCharge> + <AmountFinanced>2500000000</AmountFinanced> + <TotalOfPayments>4300435100</TotalOfPayments> + <AmortizationLine> + <AmortizationLineType>8</AmortizationLineType> + <Date>05/08/2007</Date> + <Loan1Amount>2500000000</Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount></Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>0</InterestAccrued> + <InterestPaid>0</InterestPaid> + <PrincipalPaid>0</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2500000000</PrincipalBalance> + <TotalBalance>2500000000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16666700</InterestAccrued> + <InterestPaid>16666700</InterestPaid> + <PrincipalPaid>7224600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2492775400</PrincipalBalance> + <TotalBalance>2492775400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16618500</InterestAccrued> + <InterestPaid>16618500</InterestPaid> + <PrincipalPaid>7272800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2485502600</PrincipalBalance> + <TotalBalance>2485502600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16570000</InterestAccrued> + <InterestPaid>16570000</InterestPaid> + <PrincipalPaid>7321300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2478181300</PrincipalBalance> + <TotalBalance>2478181300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16521200</InterestAccrued> + <InterestPaid>16521200</InterestPaid> + <PrincipalPaid>7370100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2470811200</PrincipalBalance> + <TotalBalance>2470811200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16472100</InterestAccrued> + <InterestPaid>16472100</InterestPaid> + <PrincipalPaid>7419200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2463392000</PrincipalBalance> + <TotalBalance>2463392000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16422600</InterestAccrued> + <InterestPaid>16422600</InterestPaid> + <PrincipalPaid>7468700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2455923300</PrincipalBalance> + <TotalBalance>2455923300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16372800</InterestAccrued> + <InterestPaid>16372800</InterestPaid> + <PrincipalPaid>7518500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2448404800</PrincipalBalance> + <TotalBalance>2448404800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2007</Date> + <Loan1Amount>2500000000</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>167239100</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>115643900</InterestAccrued> + <InterestPaid>115643900</InterestPaid> + <PrincipalPaid>51595200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2448404800</PrincipalBalance> + <TotalBalance>2448404800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16322700</InterestAccrued> + <InterestPaid>16322700</InterestPaid> + <PrincipalPaid>7568600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2440836200</PrincipalBalance> + <TotalBalance>2440836200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16272200</InterestAccrued> + <InterestPaid>16272200</InterestPaid> + <PrincipalPaid>7619100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2433217100</PrincipalBalance> + <TotalBalance>2433217100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16221400</InterestAccrued> + <InterestPaid>16221400</InterestPaid> + <PrincipalPaid>7669900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2425547200</PrincipalBalance> + <TotalBalance>2425547200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16170300</InterestAccrued> + <InterestPaid>16170300</InterestPaid> + <PrincipalPaid>7721000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2417826200</PrincipalBalance> + <TotalBalance>2417826200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16118800</InterestAccrued> + <InterestPaid>16118800</InterestPaid> + <PrincipalPaid>7772500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2410053700</PrincipalBalance> + <TotalBalance>2410053700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16067000</InterestAccrued> + <InterestPaid>16067000</InterestPaid> + <PrincipalPaid>7824300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2402229400</PrincipalBalance> + <TotalBalance>2402229400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16014900</InterestAccrued> + <InterestPaid>16014900</InterestPaid> + <PrincipalPaid>7876400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2394353000</PrincipalBalance> + <TotalBalance>2394353000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15962400</InterestAccrued> + <InterestPaid>15962400</InterestPaid> + <PrincipalPaid>7928900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2386424100</PrincipalBalance> + <TotalBalance>2386424100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15909500</InterestAccrued> + <InterestPaid>15909500</InterestPaid> + <PrincipalPaid>7981800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2378442300</PrincipalBalance> + <TotalBalance>2378442300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15856300</InterestAccrued> + <InterestPaid>15856300</InterestPaid> + <PrincipalPaid>8035000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2370407300</PrincipalBalance> + <TotalBalance>2370407300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15802700</InterestAccrued> + <InterestPaid>15802700</InterestPaid> + <PrincipalPaid>8088600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2362318700</PrincipalBalance> + <TotalBalance>2362318700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15748800</InterestAccrued> + <InterestPaid>15748800</InterestPaid> + <PrincipalPaid>8142500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2354176200</PrincipalBalance> + <TotalBalance>2354176200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2008</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>192467000</InterestAccrued> + <InterestPaid>192467000</InterestPaid> + <PrincipalPaid>94228600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2354176200</PrincipalBalance> + <TotalBalance>2354176200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15694500</InterestAccrued> + <InterestPaid>15694500</InterestPaid> + <PrincipalPaid>8196800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2345979400</PrincipalBalance> + <TotalBalance>2345979400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15639900</InterestAccrued> + <InterestPaid>15639900</InterestPaid> + <PrincipalPaid>8251400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2337728000</PrincipalBalance> + <TotalBalance>2337728000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15584900</InterestAccrued> + <InterestPaid>15584900</InterestPaid> + <PrincipalPaid>8306400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2329421600</PrincipalBalance> + <TotalBalance>2329421600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15529500</InterestAccrued> + <InterestPaid>15529500</InterestPaid> + <PrincipalPaid>8361800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2321059800</PrincipalBalance> + <TotalBalance>2321059800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15473700</InterestAccrued> + <InterestPaid>15473700</InterestPaid> + <PrincipalPaid>8417600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2312642200</PrincipalBalance> + <TotalBalance>2312642200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15417600</InterestAccrued> + <InterestPaid>15417600</InterestPaid> + <PrincipalPaid>8473700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2304168500</PrincipalBalance> + <TotalBalance>2304168500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15361100</InterestAccrued> + <InterestPaid>15361100</InterestPaid> + <PrincipalPaid>8530200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2295638300</PrincipalBalance> + <TotalBalance>2295638300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15304300</InterestAccrued> + <InterestPaid>15304300</InterestPaid> + <PrincipalPaid>8587000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2287051300</PrincipalBalance> + <TotalBalance>2287051300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15247000</InterestAccrued> + <InterestPaid>15247000</InterestPaid> + <PrincipalPaid>8644300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2278407000</PrincipalBalance> + <TotalBalance>2278407000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15189400</InterestAccrued> + <InterestPaid>15189400</InterestPaid> + <PrincipalPaid>8701900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2269705100</PrincipalBalance> + <TotalBalance>2269705100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15131400</InterestAccrued> + <InterestPaid>15131400</InterestPaid> + <PrincipalPaid>8759900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2260945200</PrincipalBalance> + <TotalBalance>2260945200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15073000</InterestAccrued> + <InterestPaid>15073000</InterestPaid> + <PrincipalPaid>8818300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2252126900</PrincipalBalance> + <TotalBalance>2252126900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2009</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>184646300</InterestAccrued> + <InterestPaid>184646300</InterestPaid> + <PrincipalPaid>102049300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2252126900</PrincipalBalance> + <TotalBalance>2252126900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15014200</InterestAccrued> + <InterestPaid>15014200</InterestPaid> + <PrincipalPaid>8877100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2243249800</PrincipalBalance> + <TotalBalance>2243249800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14955000</InterestAccrued> + <InterestPaid>14955000</InterestPaid> + <PrincipalPaid>8936300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2234313500</PrincipalBalance> + <TotalBalance>2234313500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14895400</InterestAccrued> + <InterestPaid>14895400</InterestPaid> + <PrincipalPaid>8995900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2225317600</PrincipalBalance> + <TotalBalance>2225317600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14835500</InterestAccrued> + <InterestPaid>14835500</InterestPaid> + <PrincipalPaid>9055800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2216261800</PrincipalBalance> + <TotalBalance>2216261800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14775100</InterestAccrued> + <InterestPaid>14775100</InterestPaid> + <PrincipalPaid>9116200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2207145600</PrincipalBalance> + <TotalBalance>2207145600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14714300</InterestAccrued> + <InterestPaid>14714300</InterestPaid> + <PrincipalPaid>9177000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2197968600</PrincipalBalance> + <TotalBalance>2197968600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14653100</InterestAccrued> + <InterestPaid>14653100</InterestPaid> + <PrincipalPaid>9238200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2188730400</PrincipalBalance> + <TotalBalance>2188730400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14591500</InterestAccrued> + <InterestPaid>14591500</InterestPaid> + <PrincipalPaid>9299800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2179430600</PrincipalBalance> + <TotalBalance>2179430600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14529500</InterestAccrued> + <InterestPaid>14529500</InterestPaid> + <PrincipalPaid>9361800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2170068800</PrincipalBalance> + <TotalBalance>2170068800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14467100</InterestAccrued> + <InterestPaid>14467100</InterestPaid> + <PrincipalPaid>9424200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2160644600</PrincipalBalance> + <TotalBalance>2160644600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14404300</InterestAccrued> + <InterestPaid>14404300</InterestPaid> + <PrincipalPaid>9487000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2151157600</PrincipalBalance> + <TotalBalance>2151157600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14341100</InterestAccrued> + <InterestPaid>14341100</InterestPaid> + <PrincipalPaid>9550200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2141607400</PrincipalBalance> + <TotalBalance>2141607400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2010</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>176176100</InterestAccrued> + <InterestPaid>176176100</InterestPaid> + <PrincipalPaid>110519500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2141607400</PrincipalBalance> + <TotalBalance>2141607400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14277400</InterestAccrued> + <InterestPaid>14277400</InterestPaid> + <PrincipalPaid>9613900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2131993500</PrincipalBalance> + <TotalBalance>2131993500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14213300</InterestAccrued> + <InterestPaid>14213300</InterestPaid> + <PrincipalPaid>9678000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2122315500</PrincipalBalance> + <TotalBalance>2122315500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14148800</InterestAccrued> + <InterestPaid>14148800</InterestPaid> + <PrincipalPaid>9742500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2112573000</PrincipalBalance> + <TotalBalance>2112573000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14083800</InterestAccrued> + <InterestPaid>14083800</InterestPaid> + <PrincipalPaid>9807500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2102765500</PrincipalBalance> + <TotalBalance>2102765500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14018400</InterestAccrued> + <InterestPaid>14018400</InterestPaid> + <PrincipalPaid>9872900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2092892600</PrincipalBalance> + <TotalBalance>2092892600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13952600</InterestAccrued> + <InterestPaid>13952600</InterestPaid> + <PrincipalPaid>9938700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2082953900</PrincipalBalance> + <TotalBalance>2082953900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13886400</InterestAccrued> + <InterestPaid>13886400</InterestPaid> + <PrincipalPaid>10004900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2072949000</PrincipalBalance> + <TotalBalance>2072949000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13819700</InterestAccrued> + <InterestPaid>13819700</InterestPaid> + <PrincipalPaid>10071600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2062877400</PrincipalBalance> + <TotalBalance>2062877400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13752500</InterestAccrued> + <InterestPaid>13752500</InterestPaid> + <PrincipalPaid>10138800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2052738600</PrincipalBalance> + <TotalBalance>2052738600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13684900</InterestAccrued> + <InterestPaid>13684900</InterestPaid> + <PrincipalPaid>10206400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2042532200</PrincipalBalance> + <TotalBalance>2042532200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13616900</InterestAccrued> + <InterestPaid>13616900</InterestPaid> + <PrincipalPaid>10274400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2032257800</PrincipalBalance> + <TotalBalance>2032257800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13548400</InterestAccrued> + <InterestPaid>13548400</InterestPaid> + <PrincipalPaid>10342900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2021914900</PrincipalBalance> + <TotalBalance>2021914900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2011</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>167003100</InterestAccrued> + <InterestPaid>167003100</InterestPaid> + <PrincipalPaid>119692500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2021914900</PrincipalBalance> + <TotalBalance>2021914900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13479400</InterestAccrued> + <InterestPaid>13479400</InterestPaid> + <PrincipalPaid>10411900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2011503000</PrincipalBalance> + <TotalBalance>2011503000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13410000</InterestAccrued> + <InterestPaid>13410000</InterestPaid> + <PrincipalPaid>10481300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2001021700</PrincipalBalance> + <TotalBalance>2001021700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13340100</InterestAccrued> + <InterestPaid>13340100</InterestPaid> + <PrincipalPaid>10551200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1990470500</PrincipalBalance> + <TotalBalance>1990470500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13269800</InterestAccrued> + <InterestPaid>13269800</InterestPaid> + <PrincipalPaid>10621500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1979849000</PrincipalBalance> + <TotalBalance>1979849000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13199000</InterestAccrued> + <InterestPaid>13199000</InterestPaid> + <PrincipalPaid>10692300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1969156700</PrincipalBalance> + <TotalBalance>1969156700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13127700</InterestAccrued> + <InterestPaid>13127700</InterestPaid> + <PrincipalPaid>10763600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1958393100</PrincipalBalance> + <TotalBalance>1958393100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13056000</InterestAccrued> + <InterestPaid>13056000</InterestPaid> + <PrincipalPaid>10835300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1947557800</PrincipalBalance> + <TotalBalance>1947557800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12983700</InterestAccrued> + <InterestPaid>12983700</InterestPaid> + <PrincipalPaid>10907600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1936650200</PrincipalBalance> + <TotalBalance>1936650200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12911000</InterestAccrued> + <InterestPaid>12911000</InterestPaid> + <PrincipalPaid>10980300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1925669900</PrincipalBalance> + <TotalBalance>1925669900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12837800</InterestAccrued> + <InterestPaid>12837800</InterestPaid> + <PrincipalPaid>11053500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1914616400</PrincipalBalance> + <TotalBalance>1914616400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12764100</InterestAccrued> + <InterestPaid>12764100</InterestPaid> + <PrincipalPaid>11127200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1903489200</PrincipalBalance> + <TotalBalance>1903489200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12689900</InterestAccrued> + <InterestPaid>12689900</InterestPaid> + <PrincipalPaid>11201400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1892287800</PrincipalBalance> + <TotalBalance>1892287800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2012</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>157068500</InterestAccrued> + <InterestPaid>157068500</InterestPaid> + <PrincipalPaid>129627100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1892287800</PrincipalBalance> + <TotalBalance>1892287800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12615300</InterestAccrued> + <InterestPaid>12615300</InterestPaid> + <PrincipalPaid>11276000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1881011800</PrincipalBalance> + <TotalBalance>1881011800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12540100</InterestAccrued> + <InterestPaid>12540100</InterestPaid> + <PrincipalPaid>11351200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1869660600</PrincipalBalance> + <TotalBalance>1869660600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12464400</InterestAccrued> + <InterestPaid>12464400</InterestPaid> + <PrincipalPaid>11426900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1858233700</PrincipalBalance> + <TotalBalance>1858233700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12388200</InterestAccrued> + <InterestPaid>12388200</InterestPaid> + <PrincipalPaid>11503100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1846730600</PrincipalBalance> + <TotalBalance>1846730600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12311500</InterestAccrued> + <InterestPaid>12311500</InterestPaid> + <PrincipalPaid>11579800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1835150800</PrincipalBalance> + <TotalBalance>1835150800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12234300</InterestAccrued> + <InterestPaid>12234300</InterestPaid> + <PrincipalPaid>11657000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1823493800</PrincipalBalance> + <TotalBalance>1823493800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12156600</InterestAccrued> + <InterestPaid>12156600</InterestPaid> + <PrincipalPaid>11734700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1811759100</PrincipalBalance> + <TotalBalance>1811759100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12078400</InterestAccrued> + <InterestPaid>12078400</InterestPaid> + <PrincipalPaid>11812900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1799946200</PrincipalBalance> + <TotalBalance>1799946200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11999600</InterestAccrued> + <InterestPaid>11999600</InterestPaid> + <PrincipalPaid>11891700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1788054500</PrincipalBalance> + <TotalBalance>1788054500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11920400</InterestAccrued> + <InterestPaid>11920400</InterestPaid> + <PrincipalPaid>11970900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1776083600</PrincipalBalance> + <TotalBalance>1776083600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11840600</InterestAccrued> + <InterestPaid>11840600</InterestPaid> + <PrincipalPaid>12050700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1764032900</PrincipalBalance> + <TotalBalance>1764032900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11760200</InterestAccrued> + <InterestPaid>11760200</InterestPaid> + <PrincipalPaid>12131100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1751901800</PrincipalBalance> + <TotalBalance>1751901800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2013</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>146309600</InterestAccrued> + <InterestPaid>146309600</InterestPaid> + <PrincipalPaid>140386000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1751901800</PrincipalBalance> + <TotalBalance>1751901800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11679300</InterestAccrued> + <InterestPaid>11679300</InterestPaid> + <PrincipalPaid>12212000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1739689800</PrincipalBalance> + <TotalBalance>1739689800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11597900</InterestAccrued> + <InterestPaid>11597900</InterestPaid> + <PrincipalPaid>12293400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1727396400</PrincipalBalance> + <TotalBalance>1727396400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11516000</InterestAccrued> + <InterestPaid>11516000</InterestPaid> + <PrincipalPaid>12375300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1715021100</PrincipalBalance> + <TotalBalance>1715021100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11433500</InterestAccrued> + <InterestPaid>11433500</InterestPaid> + <PrincipalPaid>12457800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1702563300</PrincipalBalance> + <TotalBalance>1702563300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11350400</InterestAccrued> + <InterestPaid>11350400</InterestPaid> + <PrincipalPaid>12540900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1690022400</PrincipalBalance> + <TotalBalance>1690022400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11266800</InterestAccrued> + <InterestPaid>11266800</InterestPaid> + <PrincipalPaid>12624500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1677397900</PrincipalBalance> + <TotalBalance>1677397900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11182700</InterestAccrued> + <InterestPaid>11182700</InterestPaid> + <PrincipalPaid>12708600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1664689300</PrincipalBalance> + <TotalBalance>1664689300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11097900</InterestAccrued> + <InterestPaid>11097900</InterestPaid> + <PrincipalPaid>12793400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1651895900</PrincipalBalance> + <TotalBalance>1651895900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11012600</InterestAccrued> + <InterestPaid>11012600</InterestPaid> + <PrincipalPaid>12878700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1639017200</PrincipalBalance> + <TotalBalance>1639017200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10926800</InterestAccrued> + <InterestPaid>10926800</InterestPaid> + <PrincipalPaid>12964500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1626052700</PrincipalBalance> + <TotalBalance>1626052700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10840400</InterestAccrued> + <InterestPaid>10840400</InterestPaid> + <PrincipalPaid>13050900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1613001800</PrincipalBalance> + <TotalBalance>1613001800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10753300</InterestAccrued> + <InterestPaid>10753300</InterestPaid> + <PrincipalPaid>13138000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1599863800</PrincipalBalance> + <TotalBalance>1599863800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2014</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>134657600</InterestAccrued> + <InterestPaid>134657600</InterestPaid> + <PrincipalPaid>152038000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1599863800</PrincipalBalance> + <TotalBalance>1599863800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10665800</InterestAccrued> + <InterestPaid>10665800</InterestPaid> + <PrincipalPaid>13225500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1586638300</PrincipalBalance> + <TotalBalance>1586638300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10577600</InterestAccrued> + <InterestPaid>10577600</InterestPaid> + <PrincipalPaid>13313700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1573324600</PrincipalBalance> + <TotalBalance>1573324600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10488800</InterestAccrued> + <InterestPaid>10488800</InterestPaid> + <PrincipalPaid>13402500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1559922100</PrincipalBalance> + <TotalBalance>1559922100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10399500</InterestAccrued> + <InterestPaid>10399500</InterestPaid> + <PrincipalPaid>13491800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1546430300</PrincipalBalance> + <TotalBalance>1546430300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10309500</InterestAccrued> + <InterestPaid>10309500</InterestPaid> + <PrincipalPaid>13581800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1532848500</PrincipalBalance> + <TotalBalance>1532848500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10219000</InterestAccrued> + <InterestPaid>10219000</InterestPaid> + <PrincipalPaid>13672300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1519176200</PrincipalBalance> + <TotalBalance>1519176200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10127800</InterestAccrued> + <InterestPaid>10127800</InterestPaid> + <PrincipalPaid>13763500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1505412700</PrincipalBalance> + <TotalBalance>1505412700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10036100</InterestAccrued> + <InterestPaid>10036100</InterestPaid> + <PrincipalPaid>13855200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1491557500</PrincipalBalance> + <TotalBalance>1491557500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9943700</InterestAccrued> + <InterestPaid>9943700</InterestPaid> + <PrincipalPaid>13947600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1477609900</PrincipalBalance> + <TotalBalance>1477609900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9850700</InterestAccrued> + <InterestPaid>9850700</InterestPaid> + <PrincipalPaid>14040600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1463569300</PrincipalBalance> + <TotalBalance>1463569300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9757100</InterestAccrued> + <InterestPaid>9757100</InterestPaid> + <PrincipalPaid>14134200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1449435100</PrincipalBalance> + <TotalBalance>1449435100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9662900</InterestAccrued> + <InterestPaid>9662900</InterestPaid> + <PrincipalPaid>14228400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1435206700</PrincipalBalance> + <TotalBalance>1435206700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2015</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>122038500</InterestAccrued> + <InterestPaid>122038500</InterestPaid> + <PrincipalPaid>164657100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1435206700</PrincipalBalance> + <TotalBalance>1435206700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9568000</InterestAccrued> + <InterestPaid>9568000</InterestPaid> + <PrincipalPaid>14323300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1420883400</PrincipalBalance> + <TotalBalance>1420883400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9472600</InterestAccrued> + <InterestPaid>9472600</InterestPaid> + <PrincipalPaid>14418700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1406464700</PrincipalBalance> + <TotalBalance>1406464700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9376400</InterestAccrued> + <InterestPaid>9376400</InterestPaid> + <PrincipalPaid>14514900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1391949800</PrincipalBalance> + <TotalBalance>1391949800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9279700</InterestAccrued> + <InterestPaid>9279700</InterestPaid> + <PrincipalPaid>14611600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1377338200</PrincipalBalance> + <TotalBalance>1377338200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9182300</InterestAccrued> + <InterestPaid>9182300</InterestPaid> + <PrincipalPaid>14709000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1362629200</PrincipalBalance> + <TotalBalance>1362629200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9084200</InterestAccrued> + <InterestPaid>9084200</InterestPaid> + <PrincipalPaid>14807100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1347822100</PrincipalBalance> + <TotalBalance>1347822100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8985500</InterestAccrued> + <InterestPaid>8985500</InterestPaid> + <PrincipalPaid>14905800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1332916300</PrincipalBalance> + <TotalBalance>1332916300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8886100</InterestAccrued> + <InterestPaid>8886100</InterestPaid> + <PrincipalPaid>15005200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1317911100</PrincipalBalance> + <TotalBalance>1317911100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8786100</InterestAccrued> + <InterestPaid>8786100</InterestPaid> + <PrincipalPaid>15105200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1302805900</PrincipalBalance> + <TotalBalance>1302805900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8685400</InterestAccrued> + <InterestPaid>8685400</InterestPaid> + <PrincipalPaid>15205900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1287600000</PrincipalBalance> + <TotalBalance>1287600000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8584000</InterestAccrued> + <InterestPaid>8584000</InterestPaid> + <PrincipalPaid>15307300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1272292700</PrincipalBalance> + <TotalBalance>1272292700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8482000</InterestAccrued> + <InterestPaid>8482000</InterestPaid> + <PrincipalPaid>15409300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1256883400</PrincipalBalance> + <TotalBalance>1256883400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2016</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>108372300</InterestAccrued> + <InterestPaid>108372300</InterestPaid> + <PrincipalPaid>178323300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1256883400</PrincipalBalance> + <TotalBalance>1256883400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8379200</InterestAccrued> + <InterestPaid>8379200</InterestPaid> + <PrincipalPaid>15512100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1241371300</PrincipalBalance> + <TotalBalance>1241371300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8275800</InterestAccrued> + <InterestPaid>8275800</InterestPaid> + <PrincipalPaid>15615500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1225755800</PrincipalBalance> + <TotalBalance>1225755800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8171700</InterestAccrued> + <InterestPaid>8171700</InterestPaid> + <PrincipalPaid>15719600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1210036200</PrincipalBalance> + <TotalBalance>1210036200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8066900</InterestAccrued> + <InterestPaid>8066900</InterestPaid> + <PrincipalPaid>15824400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1194211800</PrincipalBalance> + <TotalBalance>1194211800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7961400</InterestAccrued> + <InterestPaid>7961400</InterestPaid> + <PrincipalPaid>15929900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1178281900</PrincipalBalance> + <TotalBalance>1178281900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7855200</InterestAccrued> + <InterestPaid>7855200</InterestPaid> + <PrincipalPaid>16036100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1162245800</PrincipalBalance> + <TotalBalance>1162245800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7748300</InterestAccrued> + <InterestPaid>7748300</InterestPaid> + <PrincipalPaid>16143000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1146102800</PrincipalBalance> + <TotalBalance>1146102800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7640700</InterestAccrued> + <InterestPaid>7640700</InterestPaid> + <PrincipalPaid>16250600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1129852200</PrincipalBalance> + <TotalBalance>1129852200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7532300</InterestAccrued> + <InterestPaid>7532300</InterestPaid> + <PrincipalPaid>16359000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1113493200</PrincipalBalance> + <TotalBalance>1113493200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7423300</InterestAccrued> + <InterestPaid>7423300</InterestPaid> + <PrincipalPaid>16468000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1097025200</PrincipalBalance> + <TotalBalance>1097025200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7313500</InterestAccrued> + <InterestPaid>7313500</InterestPaid> + <PrincipalPaid>16577800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1080447400</PrincipalBalance> + <TotalBalance>1080447400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7203000</InterestAccrued> + <InterestPaid>7203000</InterestPaid> + <PrincipalPaid>16688300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1063759100</PrincipalBalance> + <TotalBalance>1063759100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2017</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>93571300</InterestAccrued> + <InterestPaid>93571300</InterestPaid> + <PrincipalPaid>193124300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1063759100</PrincipalBalance> + <TotalBalance>1063759100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7091700</InterestAccrued> + <InterestPaid>7091700</InterestPaid> + <PrincipalPaid>16799600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1046959500</PrincipalBalance> + <TotalBalance>1046959500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6979700</InterestAccrued> + <InterestPaid>6979700</InterestPaid> + <PrincipalPaid>16911600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1030047900</PrincipalBalance> + <TotalBalance>1030047900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6867000</InterestAccrued> + <InterestPaid>6867000</InterestPaid> + <PrincipalPaid>17024300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1013023600</PrincipalBalance> + <TotalBalance>1013023600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6753500</InterestAccrued> + <InterestPaid>6753500</InterestPaid> + <PrincipalPaid>17137800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>995885800</PrincipalBalance> + <TotalBalance>995885800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6639200</InterestAccrued> + <InterestPaid>6639200</InterestPaid> + <PrincipalPaid>17252100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>978633700</PrincipalBalance> + <TotalBalance>978633700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6524200</InterestAccrued> + <InterestPaid>6524200</InterestPaid> + <PrincipalPaid>17367100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>961266600</PrincipalBalance> + <TotalBalance>961266600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6408400</InterestAccrued> + <InterestPaid>6408400</InterestPaid> + <PrincipalPaid>17482900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>943783700</PrincipalBalance> + <TotalBalance>943783700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6291900</InterestAccrued> + <InterestPaid>6291900</InterestPaid> + <PrincipalPaid>17599400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>926184300</PrincipalBalance> + <TotalBalance>926184300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6174600</InterestAccrued> + <InterestPaid>6174600</InterestPaid> + <PrincipalPaid>17716700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>908467600</PrincipalBalance> + <TotalBalance>908467600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6056500</InterestAccrued> + <InterestPaid>6056500</InterestPaid> + <PrincipalPaid>17834800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>890632800</PrincipalBalance> + <TotalBalance>890632800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5937600</InterestAccrued> + <InterestPaid>5937600</InterestPaid> + <PrincipalPaid>17953700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>872679100</PrincipalBalance> + <TotalBalance>872679100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5817900</InterestAccrued> + <InterestPaid>5817900</InterestPaid> + <PrincipalPaid>18073400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>854605700</PrincipalBalance> + <TotalBalance>854605700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2018</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>77542200</InterestAccrued> + <InterestPaid>77542200</InterestPaid> + <PrincipalPaid>209153400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>854605700</PrincipalBalance> + <TotalBalance>854605700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5697400</InterestAccrued> + <InterestPaid>5697400</InterestPaid> + <PrincipalPaid>18193900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>836411800</PrincipalBalance> + <TotalBalance>836411800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5576100</InterestAccrued> + <InterestPaid>5576100</InterestPaid> + <PrincipalPaid>18315200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>818096600</PrincipalBalance> + <TotalBalance>818096600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5454000</InterestAccrued> + <InterestPaid>5454000</InterestPaid> + <PrincipalPaid>18437300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>799659300</PrincipalBalance> + <TotalBalance>799659300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5331100</InterestAccrued> + <InterestPaid>5331100</InterestPaid> + <PrincipalPaid>18560200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>781099100</PrincipalBalance> + <TotalBalance>781099100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5207300</InterestAccrued> + <InterestPaid>5207300</InterestPaid> + <PrincipalPaid>18684000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>762415100</PrincipalBalance> + <TotalBalance>762415100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5082800</InterestAccrued> + <InterestPaid>5082800</InterestPaid> + <PrincipalPaid>18808500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>743606600</PrincipalBalance> + <TotalBalance>743606600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4957400</InterestAccrued> + <InterestPaid>4957400</InterestPaid> + <PrincipalPaid>18933900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>724672700</PrincipalBalance> + <TotalBalance>724672700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4831200</InterestAccrued> + <InterestPaid>4831200</InterestPaid> + <PrincipalPaid>19060100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>705612600</PrincipalBalance> + <TotalBalance>705612600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4704100</InterestAccrued> + <InterestPaid>4704100</InterestPaid> + <PrincipalPaid>19187200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>686425400</PrincipalBalance> + <TotalBalance>686425400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4576200</InterestAccrued> + <InterestPaid>4576200</InterestPaid> + <PrincipalPaid>19315100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>667110300</PrincipalBalance> + <TotalBalance>667110300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4447400</InterestAccrued> + <InterestPaid>4447400</InterestPaid> + <PrincipalPaid>19443900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>647666400</PrincipalBalance> + <TotalBalance>647666400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4317800</InterestAccrued> + <InterestPaid>4317800</InterestPaid> + <PrincipalPaid>19573500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>628092900</PrincipalBalance> + <TotalBalance>628092900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2019</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>60182800</InterestAccrued> + <InterestPaid>60182800</InterestPaid> + <PrincipalPaid>226512800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>628092900</PrincipalBalance> + <TotalBalance>628092900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4187300</InterestAccrued> + <InterestPaid>4187300</InterestPaid> + <PrincipalPaid>19704000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>608388900</PrincipalBalance> + <TotalBalance>608388900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4055900</InterestAccrued> + <InterestPaid>4055900</InterestPaid> + <PrincipalPaid>19835400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>588553500</PrincipalBalance> + <TotalBalance>588553500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3923700</InterestAccrued> + <InterestPaid>3923700</InterestPaid> + <PrincipalPaid>19967600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>568585900</PrincipalBalance> + <TotalBalance>568585900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3790600</InterestAccrued> + <InterestPaid>3790600</InterestPaid> + <PrincipalPaid>20100700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>548485200</PrincipalBalance> + <TotalBalance>548485200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3656600</InterestAccrued> + <InterestPaid>3656600</InterestPaid> + <PrincipalPaid>20234700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>528250500</PrincipalBalance> + <TotalBalance>528250500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3521700</InterestAccrued> + <InterestPaid>3521700</InterestPaid> + <PrincipalPaid>20369600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>507880900</PrincipalBalance> + <TotalBalance>507880900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3385900</InterestAccrued> + <InterestPaid>3385900</InterestPaid> + <PrincipalPaid>20505400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>487375500</PrincipalBalance> + <TotalBalance>487375500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3249200</InterestAccrued> + <InterestPaid>3249200</InterestPaid> + <PrincipalPaid>20642100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>466733400</PrincipalBalance> + <TotalBalance>466733400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3111600</InterestAccrued> + <InterestPaid>3111600</InterestPaid> + <PrincipalPaid>20779700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>445953700</PrincipalBalance> + <TotalBalance>445953700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2973000</InterestAccrued> + <InterestPaid>2973000</InterestPaid> + <PrincipalPaid>20918300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>425035400</PrincipalBalance> + <TotalBalance>425035400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2833600</InterestAccrued> + <InterestPaid>2833600</InterestPaid> + <PrincipalPaid>21057700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>403977700</PrincipalBalance> + <TotalBalance>403977700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2693200</InterestAccrued> + <InterestPaid>2693200</InterestPaid> + <PrincipalPaid>21198100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>382779600</PrincipalBalance> + <TotalBalance>382779600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2020</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>41382300</InterestAccrued> + <InterestPaid>41382300</InterestPaid> + <PrincipalPaid>245313300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>382779600</PrincipalBalance> + <TotalBalance>382779600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2551900</InterestAccrued> + <InterestPaid>2551900</InterestPaid> + <PrincipalPaid>21339400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>361440200</PrincipalBalance> + <TotalBalance>361440200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2409600</InterestAccrued> + <InterestPaid>2409600</InterestPaid> + <PrincipalPaid>21481700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>339958500</PrincipalBalance> + <TotalBalance>339958500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2266400</InterestAccrued> + <InterestPaid>2266400</InterestPaid> + <PrincipalPaid>21624900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>318333600</PrincipalBalance> + <TotalBalance>318333600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2122200</InterestAccrued> + <InterestPaid>2122200</InterestPaid> + <PrincipalPaid>21769100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>296564500</PrincipalBalance> + <TotalBalance>296564500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1977100</InterestAccrued> + <InterestPaid>1977100</InterestPaid> + <PrincipalPaid>21914200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>274650300</PrincipalBalance> + <TotalBalance>274650300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1831000</InterestAccrued> + <InterestPaid>1831000</InterestPaid> + <PrincipalPaid>22060300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>252590000</PrincipalBalance> + <TotalBalance>252590000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1683900</InterestAccrued> + <InterestPaid>1683900</InterestPaid> + <PrincipalPaid>22207400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>230382600</PrincipalBalance> + <TotalBalance>230382600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1535900</InterestAccrued> + <InterestPaid>1535900</InterestPaid> + <PrincipalPaid>22355400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>208027200</PrincipalBalance> + <TotalBalance>208027200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1386800</InterestAccrued> + <InterestPaid>1386800</InterestPaid> + <PrincipalPaid>22504500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>185522700</PrincipalBalance> + <TotalBalance>185522700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1236800</InterestAccrued> + <InterestPaid>1236800</InterestPaid> + <PrincipalPaid>22654500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>162868200</PrincipalBalance> + <TotalBalance>162868200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1085800</InterestAccrued> + <InterestPaid>1085800</InterestPaid> + <PrincipalPaid>22805500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>140062700</PrincipalBalance> + <TotalBalance>140062700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>933800</InterestAccrued> + <InterestPaid>933800</InterestPaid> + <PrincipalPaid>22957500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>117105200</PrincipalBalance> + <TotalBalance>117105200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2021</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>21021200</InterestAccrued> + <InterestPaid>21021200</InterestPaid> + <PrincipalPaid>265674400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>117105200</PrincipalBalance> + <TotalBalance>117105200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>780700</InterestAccrued> + <InterestPaid>780700</InterestPaid> + <PrincipalPaid>23110600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>93994600</PrincipalBalance> + <TotalBalance>93994600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>626600</InterestAccrued> + <InterestPaid>626600</InterestPaid> + <PrincipalPaid>23264700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>70729900</PrincipalBalance> + <TotalBalance>70729900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>471500</InterestAccrued> + <InterestPaid>471500</InterestPaid> + <PrincipalPaid>23419800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>47310100</PrincipalBalance> + <TotalBalance>47310100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>315400</InterestAccrued> + <InterestPaid>315400</InterestPaid> + <PrincipalPaid>23575900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>23734200</PrincipalBalance> + <TotalBalance>23734200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>158200</InterestAccrued> + <InterestPaid>158200</InterestPaid> + <PrincipalPaid>23733100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1100</PrincipalBalance> + <TotalBalance>1100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>1100</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>0</InterestAccrued> + <InterestPaid>0</InterestPaid> + <PrincipalPaid>1100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>0</PrincipalBalance> + <TotalBalance>0</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2022</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>119457600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>2352400</InterestAccrued> + <InterestPaid>2352400</InterestPaid> + <PrincipalPaid>117105200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>0</PrincipalBalance> + <TotalBalance>0</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>52</AmortizationLineType> + <Date>06/30/2022</Date> + <Loan1Amount>2500000000</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>4300435100</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>1800435100</InterestAccrued> + <InterestPaid>1800435100</InterestPaid> + <PrincipalPaid>2500000000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>0</PrincipalBalance> + <TotalBalance>0</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> +</TValueAmortizationSchedule> + \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 129738e..63c8bc1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,33 @@ $:.unshift(File.dirname(__FILE__) + '/../lib/') require 'rubygems' require 'spec' require 'stater' +require 'hpricot' FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) +module CustomMatchers + def tvalue_schedule(xml_file) + control_schedule = [] + doc = Hpricot(open(File.dirname(__FILE__) + "/fixtures/tvalue_schedules/#{xml_file}")) + + lines = (doc/:tvalueamortizationschedule/:amortizationline) + lines.each do |line| + if line.search(:amortizationlinetype).innerHTML == '9' + payment = line.search(:payment1amount).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + interest_paid = line.search(:interestpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + principal_paid = line.search(:principalpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + principal_balance = line.search(:principalbalance).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + + control_schedule << Struct::Payment.new(nil, payment, principal_paid, interest_paid, principal_balance) + end + end + control_schedule + end +end + Spec::Runner.configure do |config| + config.include(CustomMatchers) config.mock_with :mocha -end \ No newline at end of file +end + diff --git a/spec/unit/amortization_spec.rb b/spec/unit/amortization_spec.rb new file mode 100644 index 0000000..d7417ae --- /dev/null +++ b/spec/unit/amortization_spec.rb @@ -0,0 +1,66 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Stater::Amortization, 'when initialized' do + + before(:each) do + @amortization = Stater::Amortization.new + end + + specify 'schedule should be an empty array' do + @amortization.schedule.should == [] + end + + specify 'principal should be nil' do + @amortization.principal.should be_nil + end + + specify 'periodic_rate should be nil' do + @amortization.periodic_rate.should be_nil + end + + specify 'periods should be nil' do + @amortization.periods.should be_nil + end + +end + +describe Stater::Amortization do + before(:each) do + principal = 250000.00 + periodic_rate = 0.08 / 12 + periods = 15 * 12 + + @amortization = Stater::Amortization.new(principal, periodic_rate, periods) + end + + it 'should correctly calculate a payment when given the principal, periodic_rate, and periods' do + @amortization.calculate_payment.should == 2389.13 + end + + it 'should return the calculated payment as a BigDecimal' do + @amortization.calculate_payment.should be_kind_of(BigDecimal) + end + + it 'should convert principal to BigDecimal' do + @amortization.principal.should be_kind_of(BigDecimal) + end + + it 'should convert periodic_rate to BigDecimal' do + @amortization.periodic_rate.should be_kind_of(BigDecimal) + end +end + +describe Stater::Amortization, 'schedule' do + before(:each) do + principal = 250000.00 + periodic_rate = 0.08 / 12 + periods = 15 * 12 + + @amortization = Stater::Amortization.new(principal, periodic_rate, periods) + end + + it 'should exactly match the TValue control schedule' + # it 'should exactly match the TValue control schedule' do + # @amortization.schedule.size.should == tvalue_schedule('FEC_example_3_3_1.xml').size + # end +end \ No newline at end of file diff --git a/test/unit/amortization_test.rb b/test/unit/amortization_test.rb index b0c5fc6..dad1f00 100644 --- a/test/unit/amortization_test.rb +++ b/test/unit/amortization_test.rb @@ -1,44 +1,44 @@ require File.dirname(__FILE__) + '/../test_helper' class Stater::AmortizationTest < Test::Unit::TestCase def test_new_amortization amortization = Stater::Amortization.new assert_equal [], amortization.schedule assert_nil amortization.principal assert_nil amortization.periodic_rate assert_nil amortization.periods end def test_payment principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 - amortization = Stater::Amortization.new(250000.00, periodic_rate, periods) + amortization = Stater::Amortization.new(principal, periodic_rate, periods) assert_kind_of BigDecimal, amortization.calculate_payment assert_equal BigDecimal('2389.13'), amortization.calculate_payment end def test_schedule principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 amortization = Stater::Amortization.new(principal, periodic_rate, periods) assert_kind_of BigDecimal, amortization.principal assert_equal BigDecimal(principal.to_s), amortization.principal assert_kind_of BigDecimal, amortization.periodic_rate assert_equal BigDecimal(periodic_rate.to_s), amortization.periodic_rate assert_kind_of Fixnum, amortization.periods assert_equal periods, amortization.periods # Compare to TValue schedules - they should match exactly assert_schedule(File.dirname(__FILE__) + "/../fixtures/FEC_example_3_3_1.xml", amortization.schedule) end end \ No newline at end of file
infused/stater
d9ca1f52fee1fcab3e1ddf2577ba5e3e5cdf034c
Convert TVM tests to RSpec
diff --git a/Rakefile b/Rakefile index d2b209b..28b8efe 100644 --- a/Rakefile +++ b/Rakefile @@ -1,19 +1,20 @@ -require "rubygems" -require "hoe" -require "spec/rake/spectask" +require 'rubygems' +require 'hoe' +require 'spec/rake/spectask' -Hoe.new("stater", "1.0.0") do |p| - p.author = "Keith Morrison" - p.test_globs = ["test/**/*_test.rb"] +Hoe.new('stater', '1.0.0') do |p| + p.author = 'Keith Morrison' + p.email = 'keithm@infused.org' + p.test_globs = ['test/**/*_test.rb'] end -desc "Run specs" +desc 'Run specs' Spec::Rake::SpecTask.new :spec do |t| t.spec_files = FileList['spec/**/*spec.rb'] end -desc "Run spec docs" +desc 'Run spec docs' Spec::Rake::SpecTask.new :specdoc do |t| - t.spec_opts = ["-f specdoc"] + t.spec_opts = ['-f specdoc'] t.spec_files = FileList['spec/**/*spec.rb'] end diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb index 775270d..cca9faa 100644 --- a/spec/unit/tvm_spec.rb +++ b/spec/unit/tvm_spec.rb @@ -1,26 +1,44 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Stater::TVM do before(:each) do @present_value = 6000.00 @future_value = 7935.08 @interest = 0.04 @years = 7 @periods_per_year = 12 - @periodic_rate = @interest / @periods_per_year - @periods = @years * @periods_per_year @delta = 0.005 end it "should calculate present value" do Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_close(@present_value, @delta) end it "should calculate future value" do Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_close(@future_value, @delta) end it "should calculate interest" do Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_close(@interest, @delta) end + + it "should caculate years" do + Stater::TVM.years(@present_value, @future_value, @interest, @periods_per_year).should be_close(@years, @delta) + end + + it "should convert simple interest to APR" do + Stater::TVM.i_to_apr(0.18, 12).should be_close(0.195, @delta) + end + + it "should convert APR to simple interest" do + Stater::TVM.apr_to_i(0.195, 12).should be_close(0.179, @delta) + end + + it "should convert APR to EAR" do + Stater::TVM.apr_to_ear(0.129, 12).should be_close(0.137, @delta) + end + + it "should convert EAR to APR" do + Stater::TVM.ear_to_apr(0.138, 12).should be_close(0.129, @delta) + end end diff --git a/test/unit/tvm_test.rb b/test/unit/tvm_test.rb deleted file mode 100644 index 5949f2d..0000000 --- a/test/unit/tvm_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class Stater::TVMTest < Test::Unit::TestCase - - def test_future_value - present_value = 6000.00 - periodic_rate = 0.04 / 12 - periods = 84 - - assert_equal '7935.08318331367', Stater::TVM.fv(present_value, 0.04, 7, 12).to_s - end - - def test_present_value - future_value = 7935.08 - periodic_rate = 0.04 / 12 - periods = 84 - - assert_equal '5999.99759298276', Stater::TVM.pv(future_value, 0.04, 7, 12).to_s - end - - def test_interest - assert_equal '0.039999942499020946229393302929', sprintf('%3.30f', Stater::TVM.interest(6000.0, 7935.08, 7, 12)) - end - - def test_years - assert_equal '6.99998995405338', Stater::TVM.years(6000.0, 7935.08, 0.04, 12).to_s - end - - def test_interest_to_apr - assert_equal '0.195618171461533', Stater::TVM.i_to_apr(0.18, 12).to_s - end - - def test_apr_to_interest - assert_equal '0.179999854440594', Stater::TVM.apr_to_i(0.195618, 12).to_s - end - - def test_apr_to_ear - assert_equal '0.137919903125943', Stater::TVM.apr_to_ear(0.1299, 12).to_s - end - - def test_ear_to_apr - assert_equal '0.129900000000001', Stater::TVM.ear_to_apr(0.137919903125943, 12).to_s - end - -end \ No newline at end of file
infused/stater
d220f62caf490e39963fc735b1a54f12d9e5a0ad
Add specs
diff --git a/Rakefile b/Rakefile index 5f417b1..d2b209b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,19 @@ require "rubygems" require "hoe" +require "spec/rake/spectask" Hoe.new("stater", "1.0.0") do |p| p.author = "Keith Morrison" p.test_globs = ["test/**/*_test.rb"] end + +desc "Run specs" +Spec::Rake::SpecTask.new :spec do |t| + t.spec_files = FileList['spec/**/*spec.rb'] +end + +desc "Run spec docs" +Spec::Rake::SpecTask.new :specdoc do |t| + t.spec_opts = ["-f specdoc"] + t.spec_files = FileList['spec/**/*spec.rb'] +end diff --git a/lib/stater/tvm.rb b/lib/stater/tvm.rb index a9c1f5d..794f6a8 100644 --- a/lib/stater/tvm.rb +++ b/lib/stater/tvm.rb @@ -1,76 +1,78 @@ module Stater class TVM include Math class << self # Calculates the future value # pv = present value - # r = periodic interest rate - # n = number of compounding periods - def fv(pv, r, n) - pv * ((1 + r)**n) + # i = simple interest rate + # n = number of years + # m = compounding periods per year + def fv(pv, i, n, m) + pv * (1 + (i/m)) ** (n*m) end # Calulates the present value # fv = future value - # r = periodic interest rate - # n = number of compounding periods - def pv(fv, r, n) - fv / ((1 + r)**n) + # i = periodic interest rate + # n = number of years + # m = compounding periods per year + def pv(fv, i, n, m) + fv / (1 + (i/m)) ** (n*m) end # Calculates the nomical interest rate # pv = present value # fv = future value # y = years # n = compounding periods per year def i(pv, fv, y, n) n * ((fv / pv) ** (1 / (y.to_f * n)) - 1) end # Calculates the number of years # pv = present value # fv = future value # r = nominal interest rate # n = compounding periods per year def y(pv, fv, r, n) Math.log(fv / pv) / (n * Math.log(1 + (r / n))) end # Converts the nomical interest rate to APR (annual percentage rate) # r = nominal interest rate # n = compounding periods per year def i_to_apr(r, n) ((1 + (r / n)) ** n) - 1 end # Converts APR (annual percentage rate) to the nomical interest rate # apr = annual percentage rate # n = compounding periods per year def apr_to_i(apr, n) n * ((1 + apr) ** (1/n.to_f) - 1) end # Converts EAR (effective annual rate) to APR (annual percentage rate) # apr = annual percentage rate # n = compounding periods per year def apr_to_ear(apr, n) ((1 + apr / n)**n) - 1 end # Converts APR (annual percentage rate) to EAR (effective annual rate) # ear = effective annual rate # n = compounding periods per year def ear_to_apr(ear, n) n * ((1 + ear)**(1 / n.to_f) - 1) end alias_method :present_value, :pv alias_method :future_value, :fv alias_method :interest, :i alias_method :years, :y alias_method :annual_interest_to_apr, :i_to_apr alias_method :apr_to_annual_interest, :apr_to_i end end end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..129738e --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +$:.unshift(File.dirname(__FILE__) + '/../lib/') +require 'rubygems' +require 'spec' +require 'stater' + +FIXTURE_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH) + +Spec::Runner.configure do |config| + config.mock_with :mocha +end \ No newline at end of file diff --git a/spec/unit/tvm_spec.rb b/spec/unit/tvm_spec.rb new file mode 100644 index 0000000..775270d --- /dev/null +++ b/spec/unit/tvm_spec.rb @@ -0,0 +1,26 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Stater::TVM do + before(:each) do + @present_value = 6000.00 + @future_value = 7935.08 + @interest = 0.04 + @years = 7 + @periods_per_year = 12 + @periodic_rate = @interest / @periods_per_year + @periods = @years * @periods_per_year + @delta = 0.005 + end + + it "should calculate present value" do + Stater::TVM.pv(@future_value, @interest, @years, @periods_per_year).should be_close(@present_value, @delta) + end + + it "should calculate future value" do + Stater::TVM.fv(@present_value, @interest, @years, @periods_per_year).should be_close(@future_value, @delta) + end + + it "should calculate interest" do + Stater::TVM.interest(@present_value, @future_value, @years, @periods_per_year).to_f.should be_close(@interest, @delta) + end +end diff --git a/test/fixtures/example_3_3_1b.csv b/test/fixtures/example_3_3_1b.csv new file mode 100644 index 0000000..1a99fe6 --- /dev/null +++ b/test/fixtures/example_3_3_1b.csv @@ -0,0 +1,234 @@ +"Example 3.3.1 with adjusted final payment" + +Compound Period: Monthly + +Nominal Annual Rate: 8.000 % + +CASH FLOW DATA + + Event Date Amount Number Period End Date +1 Loan 05/08/2007 "250,000.00" 1 +2 Payment 06/08/2007 "2,389.13" 179 Monthly 04/08/2022 +3 Payment 05/08/2022 "2,389.24" 1 + +AMORTIZATION SCHEDULE - Normal Amortization + +# Date Payment Interest Principal Balance +Loan 05/08/2007 "250,000.00" +1 06/08/2007 "2,389.13" "1,666.67" "722.46" "249,277.54" +2 07/08/2007 "2,389.13" "1,661.85" "727.28" "248,550.26" +3 08/08/2007 "2,389.13" "1,657.00" "732.13" "247,818.13" +4 09/08/2007 "2,389.13" "1,652.12" "737.01" "247,081.12" +5 10/08/2007 "2,389.13" "1,647.21" "741.92" "246,339.20" +6 11/08/2007 "2,389.13" "1,642.26" "746.87" "245,592.33" +7 12/08/2007 "2,389.13" "1,637.28" "751.85" "244,840.48" +2007 Totals "16,723.91" "11,564.39" "5,159.52" + +8 01/08/2008 "2,389.13" "1,632.27" "756.86" "244,083.62" +9 02/08/2008 "2,389.13" "1,627.22" "761.91" "243,321.71" +10 03/08/2008 "2,389.13" "1,622.14" "766.99" "242,554.72" +11 04/08/2008 "2,389.13" "1,617.03" "772.10" "241,782.62" +12 05/08/2008 "2,389.13" "1,611.88" "777.25" "241,005.37" +13 06/08/2008 "2,389.13" "1,606.70" "782.43" "240,222.94" +14 07/08/2008 "2,389.13" "1,601.49" "787.64" "239,435.30" +15 08/08/2008 "2,389.13" "1,596.24" "792.89" "238,642.41" +16 09/08/2008 "2,389.13" "1,590.95" "798.18" "237,844.23" +17 10/08/2008 "2,389.13" "1,585.63" "803.50" "237,040.73" +18 11/08/2008 "2,389.13" "1,580.27" "808.86" "236,231.87" +19 12/08/2008 "2,389.13" "1,574.88" "814.25" "235,417.62" +2008 Totals "28,669.56" "19,246.70" "9,422.86" + +20 01/08/2009 "2,389.13" "1,569.45" "819.68" "234,597.94" +21 02/08/2009 "2,389.13" "1,563.99" "825.14" "233,772.80" +22 03/08/2009 "2,389.13" "1,558.49" "830.64" "232,942.16" +23 04/08/2009 "2,389.13" "1,552.95" "836.18" "232,105.98" +24 05/08/2009 "2,389.13" "1,547.37" "841.76" "231,264.22" +25 06/08/2009 "2,389.13" "1,541.76" "847.37" "230,416.85" +26 07/08/2009 "2,389.13" "1,536.11" "853.02" "229,563.83" +27 08/08/2009 "2,389.13" "1,530.43" "858.70" "228,705.13" +28 09/08/2009 "2,389.13" "1,524.70" "864.43" "227,840.70" +29 10/08/2009 "2,389.13" "1,518.94" "870.19" "226,970.51" +30 11/08/2009 "2,389.13" "1,513.14" "875.99" "226,094.52" +31 12/08/2009 "2,389.13" "1,507.30" "881.83" "225,212.69" +2009 Totals "28,669.56" "18,464.63" "10,204.93" + +32 01/08/2010 "2,389.13" "1,501.42" "887.71" "224,324.98" +33 02/08/2010 "2,389.13" "1,495.50" "893.63" "223,431.35" +34 03/08/2010 "2,389.13" "1,489.54" "899.59" "222,531.76" +35 04/08/2010 "2,389.13" "1,483.55" "905.58" "221,626.18" +36 05/08/2010 "2,389.13" "1,477.51" "911.62" "220,714.56" +37 06/08/2010 "2,389.13" "1,471.43" "917.70" "219,796.86" +38 07/08/2010 "2,389.13" "1,465.31" "923.82" "218,873.04" +39 08/08/2010 "2,389.13" "1,459.15" "929.98" "217,943.06" +40 09/08/2010 "2,389.13" "1,452.95" "936.18" "217,006.88" +41 10/08/2010 "2,389.13" "1,446.71" "942.42" "216,064.46" +42 11/08/2010 "2,389.13" "1,440.43" "948.70" "215,115.76" +43 12/08/2010 "2,389.13" "1,434.11" "955.02" "214,160.74" +2010 Totals "28,669.56" "17,617.61" "11,051.95" + +44 01/08/2011 "2,389.13" "1,427.74" "961.39" "213,199.35" +45 02/08/2011 "2,389.13" "1,421.33" "967.80" "212,231.55" +46 03/08/2011 "2,389.13" "1,414.88" "974.25" "211,257.30" +47 04/08/2011 "2,389.13" "1,408.38" "980.75" "210,276.55" +48 05/08/2011 "2,389.13" "1,401.84" "987.29" "209,289.26" +49 06/08/2011 "2,389.13" "1,395.26" "993.87" "208,295.39" +50 07/08/2011 "2,389.13" "1,388.64" "1,000.49" "207,294.90" +51 08/08/2011 "2,389.13" "1,381.97" "1,007.16" "206,287.74" +52 09/08/2011 "2,389.13" "1,375.25" "1,013.88" "205,273.86" +53 10/08/2011 "2,389.13" "1,368.49" "1,020.64" "204,253.22" +54 11/08/2011 "2,389.13" "1,361.69" "1,027.44" "203,225.78" +55 12/08/2011 "2,389.13" "1,354.84" "1,034.29" "202,191.49" +2011 Totals "28,669.56" "16,700.31" "11,969.25" + +56 01/08/2012 "2,389.13" "1,347.94" "1,041.19" "201,150.30" +57 02/08/2012 "2,389.13" "1,341.00" "1,048.13" "200,102.17" +58 03/08/2012 "2,389.13" "1,334.01" "1,055.12" "199,047.05" +59 04/08/2012 "2,389.13" "1,326.98" "1,062.15" "197,984.90" +60 05/08/2012 "2,389.13" "1,319.90" "1,069.23" "196,915.67" +61 06/08/2012 "2,389.13" "1,312.77" "1,076.36" "195,839.31" +62 07/08/2012 "2,389.13" "1,305.60" "1,083.53" "194,755.78" +63 08/08/2012 "2,389.13" "1,298.37" "1,090.76" "193,665.02" +64 09/08/2012 "2,389.13" "1,291.10" "1,098.03" "192,566.99" +65 10/08/2012 "2,389.13" "1,283.78" "1,105.35" "191,461.64" +66 11/08/2012 "2,389.13" "1,276.41" "1,112.72" "190,348.92" +67 12/08/2012 "2,389.13" "1,268.99" "1,120.14" "189,228.78" +2012 Totals "28,669.56" "15,706.85" "12,962.71" + +68 01/08/2013 "2,389.13" "1,261.53" "1,127.60" "188,101.18" +69 02/08/2013 "2,389.13" "1,254.01" "1,135.12" "186,966.06" +70 03/08/2013 "2,389.13" "1,246.44" "1,142.69" "185,823.37" +71 04/08/2013 "2,389.13" "1,238.82" "1,150.31" "184,673.06" +72 05/08/2013 "2,389.13" "1,231.15" "1,157.98" "183,515.08" +73 06/08/2013 "2,389.13" "1,223.43" "1,165.70" "182,349.38" +74 07/08/2013 "2,389.13" "1,215.66" "1,173.47" "181,175.91" +75 08/08/2013 "2,389.13" "1,207.84" "1,181.29" "179,994.62" +76 09/08/2013 "2,389.13" "1,199.96" "1,189.17" "178,805.45" +77 10/08/2013 "2,389.13" "1,192.04" "1,197.09" "177,608.36" +78 11/08/2013 "2,389.13" "1,184.06" "1,205.07" "176,403.29" +79 12/08/2013 "2,389.13" "1,176.02" "1,213.11" "175,190.18" +2013 Totals "28,669.56" "14,630.96" "14,038.60" + +80 01/08/2014 "2,389.13" "1,167.93" "1,221.20" "173,968.98" +81 02/08/2014 "2,389.13" "1,159.79" "1,229.34" "172,739.64" +82 03/08/2014 "2,389.13" "1,151.60" "1,237.53" "171,502.11" +83 04/08/2014 "2,389.13" "1,143.35" "1,245.78" "170,256.33" +84 05/08/2014 "2,389.13" "1,135.04" "1,254.09" "169,002.24" +85 06/08/2014 "2,389.13" "1,126.68" "1,262.45" "167,739.79" +86 07/08/2014 "2,389.13" "1,118.27" "1,270.86" "166,468.93" +87 08/08/2014 "2,389.13" "1,109.79" "1,279.34" "165,189.59" +88 09/08/2014 "2,389.13" "1,101.26" "1,287.87" "163,901.72" +89 10/08/2014 "2,389.13" "1,092.68" "1,296.45" "162,605.27" +90 11/08/2014 "2,389.13" "1,084.04" "1,305.09" "161,300.18" +91 12/08/2014 "2,389.13" "1,075.33" "1,313.80" "159,986.38" +2014 Totals "28,669.56" "13,465.76" "15,203.80" + +92 01/08/2015 "2,389.13" "1,066.58" "1,322.55" "158,663.83" +93 02/08/2015 "2,389.13" "1,057.76" "1,331.37" "157,332.46" +94 03/08/2015 "2,389.13" "1,048.88" "1,340.25" "155,992.21" +95 04/08/2015 "2,389.13" "1,039.95" "1,349.18" "154,643.03" +96 05/08/2015 "2,389.13" "1,030.95" "1,358.18" "153,284.85" +97 06/08/2015 "2,389.13" "1,021.90" "1,367.23" "151,917.62" +98 07/08/2015 "2,389.13" "1,012.78" "1,376.35" "150,541.27" +99 08/08/2015 "2,389.13" "1,003.61" "1,385.52" "149,155.75" +100 09/08/2015 "2,389.13" "994.37" "1,394.76" "147,760.99" +101 10/08/2015 "2,389.13" "985.07" "1,404.06" "146,356.93" +102 11/08/2015 "2,389.13" "975.71" "1,413.42" "144,943.51" +103 12/08/2015 "2,389.13" "966.29" "1,422.84" "143,520.67" +2015 Totals "28,669.56" "12,203.85" "16,465.71" + +104 01/08/2016 "2,389.13" "956.80" "1,432.33" "142,088.34" +105 02/08/2016 "2,389.13" "947.26" "1,441.87" "140,646.47" +106 03/08/2016 "2,389.13" "937.64" "1,451.49" "139,194.98" +107 04/08/2016 "2,389.13" "927.97" "1,461.16" "137,733.82" +108 05/08/2016 "2,389.13" "918.23" "1,470.90" "136,262.92" +109 06/08/2016 "2,389.13" "908.42" "1,480.71" "134,782.21" +110 07/08/2016 "2,389.13" "898.55" "1,490.58" "133,291.63" +111 08/08/2016 "2,389.13" "888.61" "1,500.52" "131,791.11" +112 09/08/2016 "2,389.13" "878.61" "1,510.52" "130,280.59" +113 10/08/2016 "2,389.13" "868.54" "1,520.59" "128,760.00" +114 11/08/2016 "2,389.13" "858.40" "1,530.73" "127,229.27" +115 12/08/2016 "2,389.13" "848.20" "1,540.93" "125,688.34" +2016 Totals "28,669.56" "10,837.23" "17,832.33" + +116 01/08/2017 "2,389.13" "837.92" "1,551.21" "124,137.13" +117 02/08/2017 "2,389.13" "827.58" "1,561.55" "122,575.58" +118 03/08/2017 "2,389.13" "817.17" "1,571.96" "121,003.62" +119 04/08/2017 "2,389.13" "806.69" "1,582.44" "119,421.18" +120 05/08/2017 "2,389.13" "796.14" "1,592.99" "117,828.19" +121 06/08/2017 "2,389.13" "785.52" "1,603.61" "116,224.58" +122 07/08/2017 "2,389.13" "774.83" "1,614.30" "114,610.28" +123 08/08/2017 "2,389.13" "764.07" "1,625.06" "112,985.22" +124 09/08/2017 "2,389.13" "753.23" "1,635.90" "111,349.32" +125 10/08/2017 "2,389.13" "742.33" "1,646.80" "109,702.52" +126 11/08/2017 "2,389.13" "731.35" "1,657.78" "108,044.74" +127 12/08/2017 "2,389.13" "720.30" "1,668.83" "106,375.91" +2017 Totals "28,669.56" "9,357.13" "19,312.43" + +128 01/08/2018 "2,389.13" "709.17" "1,679.96" "104,695.95" +129 02/08/2018 "2,389.13" "697.97" "1,691.16" "103,004.79" +130 03/08/2018 "2,389.13" "686.70" "1,702.43" "101,302.36" +131 04/08/2018 "2,389.13" "675.35" "1,713.78" "99,588.58" +132 05/08/2018 "2,389.13" "663.92" "1,725.21" "97,863.37" +133 06/08/2018 "2,389.13" "652.42" "1,736.71" "96,126.66" +134 07/08/2018 "2,389.13" "640.84" "1,748.29" "94,378.37" +135 08/08/2018 "2,389.13" "629.19" "1,759.94" "92,618.43" +136 09/08/2018 "2,389.13" "617.46" "1,771.67" "90,846.76" +137 10/08/2018 "2,389.13" "605.65" "1,783.48" "89,063.28" +138 11/08/2018 "2,389.13" "593.76" "1,795.37" "87,267.91" +139 12/08/2018 "2,389.13" "581.79" "1,807.34" "85,460.57" +2018 Totals "28,669.56" "7,754.22" "20,915.34" + +140 01/08/2019 "2,389.13" "569.74" "1,819.39" "83,641.18" +141 02/08/2019 "2,389.13" "557.61" "1,831.52" "81,809.66" +142 03/08/2019 "2,389.13" "545.40" "1,843.73" "79,965.93" +143 04/08/2019 "2,389.13" "533.11" "1,856.02" "78,109.91" +144 05/08/2019 "2,389.13" "520.73" "1,868.40" "76,241.51" +145 06/08/2019 "2,389.13" "508.28" "1,880.85" "74,360.66" +146 07/08/2019 "2,389.13" "495.74" "1,893.39" "72,467.27" +147 08/08/2019 "2,389.13" "483.12" "1,906.01" "70,561.26" +148 09/08/2019 "2,389.13" "470.41" "1,918.72" "68,642.54" +149 10/08/2019 "2,389.13" "457.62" "1,931.51" "66,711.03" +150 11/08/2019 "2,389.13" "444.74" "1,944.39" "64,766.64" +151 12/08/2019 "2,389.13" "431.78" "1,957.35" "62,809.29" +2019 Totals "28,669.56" "6,018.28" "22,651.28" + +152 01/08/2020 "2,389.13" "418.73" "1,970.40" "60,838.89" +153 02/08/2020 "2,389.13" "405.59" "1,983.54" "58,855.35" +154 03/08/2020 "2,389.13" "392.37" "1,996.76" "56,858.59" +155 04/08/2020 "2,389.13" "379.06" "2,010.07" "54,848.52" +156 05/08/2020 "2,389.13" "365.66" "2,023.47" "52,825.05" +157 06/08/2020 "2,389.13" "352.17" "2,036.96" "50,788.09" +158 07/08/2020 "2,389.13" "338.59" "2,050.54" "48,737.55" +159 08/08/2020 "2,389.13" "324.92" "2,064.21" "46,673.34" +160 09/08/2020 "2,389.13" "311.16" "2,077.97" "44,595.37" +161 10/08/2020 "2,389.13" "297.30" "2,091.83" "42,503.54" +162 11/08/2020 "2,389.13" "283.36" "2,105.77" "40,397.77" +163 12/08/2020 "2,389.13" "269.32" "2,119.81" "38,277.96" +2020 Totals "28,669.56" "4,138.23" "24,531.33" + +164 01/08/2021 "2,389.13" "255.19" "2,133.94" "36,144.02" +165 02/08/2021 "2,389.13" "240.96" "2,148.17" "33,995.85" +166 03/08/2021 "2,389.13" "226.64" "2,162.49" "31,833.36" +167 04/08/2021 "2,389.13" "212.22" "2,176.91" "29,656.45" +168 05/08/2021 "2,389.13" "197.71" "2,191.42" "27,465.03" +169 06/08/2021 "2,389.13" "183.10" "2,206.03" "25,259.00" +170 07/08/2021 "2,389.13" "168.39" "2,220.74" "23,038.26" +171 08/08/2021 "2,389.13" "153.59" "2,235.54" "20,802.72" +172 09/08/2021 "2,389.13" "138.68" "2,250.45" "18,552.27" +173 10/08/2021 "2,389.13" "123.68" "2,265.45" "16,286.82" +174 11/08/2021 "2,389.13" "108.58" "2,280.55" "14,006.27" +175 12/08/2021 "2,389.13" "93.38" "2,295.75" "11,710.52" +2021 Totals "28,669.56" "2,102.12" "26,567.44" + +176 01/08/2022 "2,389.13" "78.07" "2,311.06" "9,399.46" +177 02/08/2022 "2,389.13" "62.66" "2,326.47" "7,072.99" +178 03/08/2022 "2,389.13" "47.15" "2,341.98" "4,731.01" +179 04/08/2022 "2,389.13" "31.54" "2,357.59" "2,373.42" +180 05/08/2022 "2,389.24" "15.82" "2,373.42" "0.00" +2022 Totals "11,945.76" "235.24" "11,710.52" + + +Grand Totals "430,043.51" "180,043.51" "250,000.00" + + + \ No newline at end of file diff --git a/test/fixtures/example_3_3_1b.xml b/test/fixtures/example_3_3_1b.xml new file mode 100644 index 0000000..dd5802a --- /dev/null +++ b/test/fixtures/example_3_3_1b.xml @@ -0,0 +1,3575 @@ +<?xml version='1.0' encoding='windows-1252'?> +<TValueAmortizationSchedule> + <Rounding>0</Rounding> + <Compounding>6</Compounding> + <NominalAnnualRate>0.08</NominalAnnualRate> + <APR>0.08</APR> + <FinanceCharge>1800435100</FinanceCharge> + <AmountFinanced>2500000000</AmountFinanced> + <TotalOfPayments>4300435100</TotalOfPayments> + <AmortizationLine> + <AmortizationLineType>8</AmortizationLineType> + <Date>05/08/2007</Date> + <Loan1Amount>2500000000</Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount></Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>0</InterestAccrued> + <InterestPaid>0</InterestPaid> + <PrincipalPaid>0</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2500000000</PrincipalBalance> + <TotalBalance>2500000000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16666700</InterestAccrued> + <InterestPaid>16666700</InterestPaid> + <PrincipalPaid>7224600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2492775400</PrincipalBalance> + <TotalBalance>2492775400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16618500</InterestAccrued> + <InterestPaid>16618500</InterestPaid> + <PrincipalPaid>7272800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2485502600</PrincipalBalance> + <TotalBalance>2485502600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16570000</InterestAccrued> + <InterestPaid>16570000</InterestPaid> + <PrincipalPaid>7321300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2478181300</PrincipalBalance> + <TotalBalance>2478181300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16521200</InterestAccrued> + <InterestPaid>16521200</InterestPaid> + <PrincipalPaid>7370100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2470811200</PrincipalBalance> + <TotalBalance>2470811200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16472100</InterestAccrued> + <InterestPaid>16472100</InterestPaid> + <PrincipalPaid>7419200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2463392000</PrincipalBalance> + <TotalBalance>2463392000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16422600</InterestAccrued> + <InterestPaid>16422600</InterestPaid> + <PrincipalPaid>7468700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2455923300</PrincipalBalance> + <TotalBalance>2455923300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2007</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16372800</InterestAccrued> + <InterestPaid>16372800</InterestPaid> + <PrincipalPaid>7518500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2448404800</PrincipalBalance> + <TotalBalance>2448404800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2007</Date> + <Loan1Amount>2500000000</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>167239100</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>115643900</InterestAccrued> + <InterestPaid>115643900</InterestPaid> + <PrincipalPaid>51595200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2448404800</PrincipalBalance> + <TotalBalance>2448404800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16322700</InterestAccrued> + <InterestPaid>16322700</InterestPaid> + <PrincipalPaid>7568600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2440836200</PrincipalBalance> + <TotalBalance>2440836200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16272200</InterestAccrued> + <InterestPaid>16272200</InterestPaid> + <PrincipalPaid>7619100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2433217100</PrincipalBalance> + <TotalBalance>2433217100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16221400</InterestAccrued> + <InterestPaid>16221400</InterestPaid> + <PrincipalPaid>7669900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2425547200</PrincipalBalance> + <TotalBalance>2425547200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16170300</InterestAccrued> + <InterestPaid>16170300</InterestPaid> + <PrincipalPaid>7721000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2417826200</PrincipalBalance> + <TotalBalance>2417826200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16118800</InterestAccrued> + <InterestPaid>16118800</InterestPaid> + <PrincipalPaid>7772500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2410053700</PrincipalBalance> + <TotalBalance>2410053700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16067000</InterestAccrued> + <InterestPaid>16067000</InterestPaid> + <PrincipalPaid>7824300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2402229400</PrincipalBalance> + <TotalBalance>2402229400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>16014900</InterestAccrued> + <InterestPaid>16014900</InterestPaid> + <PrincipalPaid>7876400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2394353000</PrincipalBalance> + <TotalBalance>2394353000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15962400</InterestAccrued> + <InterestPaid>15962400</InterestPaid> + <PrincipalPaid>7928900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2386424100</PrincipalBalance> + <TotalBalance>2386424100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15909500</InterestAccrued> + <InterestPaid>15909500</InterestPaid> + <PrincipalPaid>7981800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2378442300</PrincipalBalance> + <TotalBalance>2378442300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15856300</InterestAccrued> + <InterestPaid>15856300</InterestPaid> + <PrincipalPaid>8035000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2370407300</PrincipalBalance> + <TotalBalance>2370407300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15802700</InterestAccrued> + <InterestPaid>15802700</InterestPaid> + <PrincipalPaid>8088600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2362318700</PrincipalBalance> + <TotalBalance>2362318700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2008</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15748800</InterestAccrued> + <InterestPaid>15748800</InterestPaid> + <PrincipalPaid>8142500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2354176200</PrincipalBalance> + <TotalBalance>2354176200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2008</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>192467000</InterestAccrued> + <InterestPaid>192467000</InterestPaid> + <PrincipalPaid>94228600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2354176200</PrincipalBalance> + <TotalBalance>2354176200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15694500</InterestAccrued> + <InterestPaid>15694500</InterestPaid> + <PrincipalPaid>8196800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2345979400</PrincipalBalance> + <TotalBalance>2345979400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15639900</InterestAccrued> + <InterestPaid>15639900</InterestPaid> + <PrincipalPaid>8251400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2337728000</PrincipalBalance> + <TotalBalance>2337728000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15584900</InterestAccrued> + <InterestPaid>15584900</InterestPaid> + <PrincipalPaid>8306400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2329421600</PrincipalBalance> + <TotalBalance>2329421600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15529500</InterestAccrued> + <InterestPaid>15529500</InterestPaid> + <PrincipalPaid>8361800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2321059800</PrincipalBalance> + <TotalBalance>2321059800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15473700</InterestAccrued> + <InterestPaid>15473700</InterestPaid> + <PrincipalPaid>8417600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2312642200</PrincipalBalance> + <TotalBalance>2312642200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15417600</InterestAccrued> + <InterestPaid>15417600</InterestPaid> + <PrincipalPaid>8473700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2304168500</PrincipalBalance> + <TotalBalance>2304168500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15361100</InterestAccrued> + <InterestPaid>15361100</InterestPaid> + <PrincipalPaid>8530200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2295638300</PrincipalBalance> + <TotalBalance>2295638300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15304300</InterestAccrued> + <InterestPaid>15304300</InterestPaid> + <PrincipalPaid>8587000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2287051300</PrincipalBalance> + <TotalBalance>2287051300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15247000</InterestAccrued> + <InterestPaid>15247000</InterestPaid> + <PrincipalPaid>8644300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2278407000</PrincipalBalance> + <TotalBalance>2278407000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15189400</InterestAccrued> + <InterestPaid>15189400</InterestPaid> + <PrincipalPaid>8701900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2269705100</PrincipalBalance> + <TotalBalance>2269705100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15131400</InterestAccrued> + <InterestPaid>15131400</InterestPaid> + <PrincipalPaid>8759900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2260945200</PrincipalBalance> + <TotalBalance>2260945200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2009</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15073000</InterestAccrued> + <InterestPaid>15073000</InterestPaid> + <PrincipalPaid>8818300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2252126900</PrincipalBalance> + <TotalBalance>2252126900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2009</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>184646300</InterestAccrued> + <InterestPaid>184646300</InterestPaid> + <PrincipalPaid>102049300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2252126900</PrincipalBalance> + <TotalBalance>2252126900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>15014200</InterestAccrued> + <InterestPaid>15014200</InterestPaid> + <PrincipalPaid>8877100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2243249800</PrincipalBalance> + <TotalBalance>2243249800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14955000</InterestAccrued> + <InterestPaid>14955000</InterestPaid> + <PrincipalPaid>8936300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2234313500</PrincipalBalance> + <TotalBalance>2234313500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14895400</InterestAccrued> + <InterestPaid>14895400</InterestPaid> + <PrincipalPaid>8995900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2225317600</PrincipalBalance> + <TotalBalance>2225317600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14835500</InterestAccrued> + <InterestPaid>14835500</InterestPaid> + <PrincipalPaid>9055800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2216261800</PrincipalBalance> + <TotalBalance>2216261800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14775100</InterestAccrued> + <InterestPaid>14775100</InterestPaid> + <PrincipalPaid>9116200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2207145600</PrincipalBalance> + <TotalBalance>2207145600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14714300</InterestAccrued> + <InterestPaid>14714300</InterestPaid> + <PrincipalPaid>9177000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2197968600</PrincipalBalance> + <TotalBalance>2197968600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14653100</InterestAccrued> + <InterestPaid>14653100</InterestPaid> + <PrincipalPaid>9238200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2188730400</PrincipalBalance> + <TotalBalance>2188730400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14591500</InterestAccrued> + <InterestPaid>14591500</InterestPaid> + <PrincipalPaid>9299800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2179430600</PrincipalBalance> + <TotalBalance>2179430600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14529500</InterestAccrued> + <InterestPaid>14529500</InterestPaid> + <PrincipalPaid>9361800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2170068800</PrincipalBalance> + <TotalBalance>2170068800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14467100</InterestAccrued> + <InterestPaid>14467100</InterestPaid> + <PrincipalPaid>9424200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2160644600</PrincipalBalance> + <TotalBalance>2160644600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14404300</InterestAccrued> + <InterestPaid>14404300</InterestPaid> + <PrincipalPaid>9487000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2151157600</PrincipalBalance> + <TotalBalance>2151157600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2010</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14341100</InterestAccrued> + <InterestPaid>14341100</InterestPaid> + <PrincipalPaid>9550200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2141607400</PrincipalBalance> + <TotalBalance>2141607400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2010</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>176176100</InterestAccrued> + <InterestPaid>176176100</InterestPaid> + <PrincipalPaid>110519500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2141607400</PrincipalBalance> + <TotalBalance>2141607400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14277400</InterestAccrued> + <InterestPaid>14277400</InterestPaid> + <PrincipalPaid>9613900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2131993500</PrincipalBalance> + <TotalBalance>2131993500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14213300</InterestAccrued> + <InterestPaid>14213300</InterestPaid> + <PrincipalPaid>9678000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2122315500</PrincipalBalance> + <TotalBalance>2122315500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14148800</InterestAccrued> + <InterestPaid>14148800</InterestPaid> + <PrincipalPaid>9742500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2112573000</PrincipalBalance> + <TotalBalance>2112573000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14083800</InterestAccrued> + <InterestPaid>14083800</InterestPaid> + <PrincipalPaid>9807500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2102765500</PrincipalBalance> + <TotalBalance>2102765500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>14018400</InterestAccrued> + <InterestPaid>14018400</InterestPaid> + <PrincipalPaid>9872900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2092892600</PrincipalBalance> + <TotalBalance>2092892600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13952600</InterestAccrued> + <InterestPaid>13952600</InterestPaid> + <PrincipalPaid>9938700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2082953900</PrincipalBalance> + <TotalBalance>2082953900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13886400</InterestAccrued> + <InterestPaid>13886400</InterestPaid> + <PrincipalPaid>10004900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2072949000</PrincipalBalance> + <TotalBalance>2072949000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13819700</InterestAccrued> + <InterestPaid>13819700</InterestPaid> + <PrincipalPaid>10071600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2062877400</PrincipalBalance> + <TotalBalance>2062877400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13752500</InterestAccrued> + <InterestPaid>13752500</InterestPaid> + <PrincipalPaid>10138800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2052738600</PrincipalBalance> + <TotalBalance>2052738600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13684900</InterestAccrued> + <InterestPaid>13684900</InterestPaid> + <PrincipalPaid>10206400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2042532200</PrincipalBalance> + <TotalBalance>2042532200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13616900</InterestAccrued> + <InterestPaid>13616900</InterestPaid> + <PrincipalPaid>10274400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2032257800</PrincipalBalance> + <TotalBalance>2032257800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2011</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13548400</InterestAccrued> + <InterestPaid>13548400</InterestPaid> + <PrincipalPaid>10342900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2021914900</PrincipalBalance> + <TotalBalance>2021914900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2011</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>167003100</InterestAccrued> + <InterestPaid>167003100</InterestPaid> + <PrincipalPaid>119692500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2021914900</PrincipalBalance> + <TotalBalance>2021914900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13479400</InterestAccrued> + <InterestPaid>13479400</InterestPaid> + <PrincipalPaid>10411900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2011503000</PrincipalBalance> + <TotalBalance>2011503000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13410000</InterestAccrued> + <InterestPaid>13410000</InterestPaid> + <PrincipalPaid>10481300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>2001021700</PrincipalBalance> + <TotalBalance>2001021700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13340100</InterestAccrued> + <InterestPaid>13340100</InterestPaid> + <PrincipalPaid>10551200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1990470500</PrincipalBalance> + <TotalBalance>1990470500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13269800</InterestAccrued> + <InterestPaid>13269800</InterestPaid> + <PrincipalPaid>10621500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1979849000</PrincipalBalance> + <TotalBalance>1979849000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13199000</InterestAccrued> + <InterestPaid>13199000</InterestPaid> + <PrincipalPaid>10692300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1969156700</PrincipalBalance> + <TotalBalance>1969156700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13127700</InterestAccrued> + <InterestPaid>13127700</InterestPaid> + <PrincipalPaid>10763600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1958393100</PrincipalBalance> + <TotalBalance>1958393100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>13056000</InterestAccrued> + <InterestPaid>13056000</InterestPaid> + <PrincipalPaid>10835300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1947557800</PrincipalBalance> + <TotalBalance>1947557800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12983700</InterestAccrued> + <InterestPaid>12983700</InterestPaid> + <PrincipalPaid>10907600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1936650200</PrincipalBalance> + <TotalBalance>1936650200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12911000</InterestAccrued> + <InterestPaid>12911000</InterestPaid> + <PrincipalPaid>10980300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1925669900</PrincipalBalance> + <TotalBalance>1925669900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12837800</InterestAccrued> + <InterestPaid>12837800</InterestPaid> + <PrincipalPaid>11053500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1914616400</PrincipalBalance> + <TotalBalance>1914616400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12764100</InterestAccrued> + <InterestPaid>12764100</InterestPaid> + <PrincipalPaid>11127200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1903489200</PrincipalBalance> + <TotalBalance>1903489200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2012</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12689900</InterestAccrued> + <InterestPaid>12689900</InterestPaid> + <PrincipalPaid>11201400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1892287800</PrincipalBalance> + <TotalBalance>1892287800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2012</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>157068500</InterestAccrued> + <InterestPaid>157068500</InterestPaid> + <PrincipalPaid>129627100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1892287800</PrincipalBalance> + <TotalBalance>1892287800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12615300</InterestAccrued> + <InterestPaid>12615300</InterestPaid> + <PrincipalPaid>11276000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1881011800</PrincipalBalance> + <TotalBalance>1881011800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12540100</InterestAccrued> + <InterestPaid>12540100</InterestPaid> + <PrincipalPaid>11351200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1869660600</PrincipalBalance> + <TotalBalance>1869660600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12464400</InterestAccrued> + <InterestPaid>12464400</InterestPaid> + <PrincipalPaid>11426900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1858233700</PrincipalBalance> + <TotalBalance>1858233700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12388200</InterestAccrued> + <InterestPaid>12388200</InterestPaid> + <PrincipalPaid>11503100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1846730600</PrincipalBalance> + <TotalBalance>1846730600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12311500</InterestAccrued> + <InterestPaid>12311500</InterestPaid> + <PrincipalPaid>11579800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1835150800</PrincipalBalance> + <TotalBalance>1835150800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12234300</InterestAccrued> + <InterestPaid>12234300</InterestPaid> + <PrincipalPaid>11657000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1823493800</PrincipalBalance> + <TotalBalance>1823493800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12156600</InterestAccrued> + <InterestPaid>12156600</InterestPaid> + <PrincipalPaid>11734700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1811759100</PrincipalBalance> + <TotalBalance>1811759100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>12078400</InterestAccrued> + <InterestPaid>12078400</InterestPaid> + <PrincipalPaid>11812900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1799946200</PrincipalBalance> + <TotalBalance>1799946200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11999600</InterestAccrued> + <InterestPaid>11999600</InterestPaid> + <PrincipalPaid>11891700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1788054500</PrincipalBalance> + <TotalBalance>1788054500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11920400</InterestAccrued> + <InterestPaid>11920400</InterestPaid> + <PrincipalPaid>11970900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1776083600</PrincipalBalance> + <TotalBalance>1776083600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11840600</InterestAccrued> + <InterestPaid>11840600</InterestPaid> + <PrincipalPaid>12050700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1764032900</PrincipalBalance> + <TotalBalance>1764032900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2013</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11760200</InterestAccrued> + <InterestPaid>11760200</InterestPaid> + <PrincipalPaid>12131100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1751901800</PrincipalBalance> + <TotalBalance>1751901800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2013</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>146309600</InterestAccrued> + <InterestPaid>146309600</InterestPaid> + <PrincipalPaid>140386000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1751901800</PrincipalBalance> + <TotalBalance>1751901800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11679300</InterestAccrued> + <InterestPaid>11679300</InterestPaid> + <PrincipalPaid>12212000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1739689800</PrincipalBalance> + <TotalBalance>1739689800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11597900</InterestAccrued> + <InterestPaid>11597900</InterestPaid> + <PrincipalPaid>12293400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1727396400</PrincipalBalance> + <TotalBalance>1727396400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11516000</InterestAccrued> + <InterestPaid>11516000</InterestPaid> + <PrincipalPaid>12375300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1715021100</PrincipalBalance> + <TotalBalance>1715021100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11433500</InterestAccrued> + <InterestPaid>11433500</InterestPaid> + <PrincipalPaid>12457800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1702563300</PrincipalBalance> + <TotalBalance>1702563300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11350400</InterestAccrued> + <InterestPaid>11350400</InterestPaid> + <PrincipalPaid>12540900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1690022400</PrincipalBalance> + <TotalBalance>1690022400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11266800</InterestAccrued> + <InterestPaid>11266800</InterestPaid> + <PrincipalPaid>12624500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1677397900</PrincipalBalance> + <TotalBalance>1677397900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11182700</InterestAccrued> + <InterestPaid>11182700</InterestPaid> + <PrincipalPaid>12708600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1664689300</PrincipalBalance> + <TotalBalance>1664689300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11097900</InterestAccrued> + <InterestPaid>11097900</InterestPaid> + <PrincipalPaid>12793400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1651895900</PrincipalBalance> + <TotalBalance>1651895900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>11012600</InterestAccrued> + <InterestPaid>11012600</InterestPaid> + <PrincipalPaid>12878700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1639017200</PrincipalBalance> + <TotalBalance>1639017200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10926800</InterestAccrued> + <InterestPaid>10926800</InterestPaid> + <PrincipalPaid>12964500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1626052700</PrincipalBalance> + <TotalBalance>1626052700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10840400</InterestAccrued> + <InterestPaid>10840400</InterestPaid> + <PrincipalPaid>13050900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1613001800</PrincipalBalance> + <TotalBalance>1613001800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2014</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10753300</InterestAccrued> + <InterestPaid>10753300</InterestPaid> + <PrincipalPaid>13138000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1599863800</PrincipalBalance> + <TotalBalance>1599863800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2014</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>134657600</InterestAccrued> + <InterestPaid>134657600</InterestPaid> + <PrincipalPaid>152038000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1599863800</PrincipalBalance> + <TotalBalance>1599863800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10665800</InterestAccrued> + <InterestPaid>10665800</InterestPaid> + <PrincipalPaid>13225500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1586638300</PrincipalBalance> + <TotalBalance>1586638300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10577600</InterestAccrued> + <InterestPaid>10577600</InterestPaid> + <PrincipalPaid>13313700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1573324600</PrincipalBalance> + <TotalBalance>1573324600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10488800</InterestAccrued> + <InterestPaid>10488800</InterestPaid> + <PrincipalPaid>13402500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1559922100</PrincipalBalance> + <TotalBalance>1559922100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10399500</InterestAccrued> + <InterestPaid>10399500</InterestPaid> + <PrincipalPaid>13491800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1546430300</PrincipalBalance> + <TotalBalance>1546430300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10309500</InterestAccrued> + <InterestPaid>10309500</InterestPaid> + <PrincipalPaid>13581800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1532848500</PrincipalBalance> + <TotalBalance>1532848500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10219000</InterestAccrued> + <InterestPaid>10219000</InterestPaid> + <PrincipalPaid>13672300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1519176200</PrincipalBalance> + <TotalBalance>1519176200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10127800</InterestAccrued> + <InterestPaid>10127800</InterestPaid> + <PrincipalPaid>13763500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1505412700</PrincipalBalance> + <TotalBalance>1505412700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>10036100</InterestAccrued> + <InterestPaid>10036100</InterestPaid> + <PrincipalPaid>13855200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1491557500</PrincipalBalance> + <TotalBalance>1491557500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9943700</InterestAccrued> + <InterestPaid>9943700</InterestPaid> + <PrincipalPaid>13947600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1477609900</PrincipalBalance> + <TotalBalance>1477609900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9850700</InterestAccrued> + <InterestPaid>9850700</InterestPaid> + <PrincipalPaid>14040600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1463569300</PrincipalBalance> + <TotalBalance>1463569300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9757100</InterestAccrued> + <InterestPaid>9757100</InterestPaid> + <PrincipalPaid>14134200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1449435100</PrincipalBalance> + <TotalBalance>1449435100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2015</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9662900</InterestAccrued> + <InterestPaid>9662900</InterestPaid> + <PrincipalPaid>14228400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1435206700</PrincipalBalance> + <TotalBalance>1435206700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2015</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>122038500</InterestAccrued> + <InterestPaid>122038500</InterestPaid> + <PrincipalPaid>164657100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1435206700</PrincipalBalance> + <TotalBalance>1435206700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9568000</InterestAccrued> + <InterestPaid>9568000</InterestPaid> + <PrincipalPaid>14323300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1420883400</PrincipalBalance> + <TotalBalance>1420883400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9472600</InterestAccrued> + <InterestPaid>9472600</InterestPaid> + <PrincipalPaid>14418700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1406464700</PrincipalBalance> + <TotalBalance>1406464700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9376400</InterestAccrued> + <InterestPaid>9376400</InterestPaid> + <PrincipalPaid>14514900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1391949800</PrincipalBalance> + <TotalBalance>1391949800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9279700</InterestAccrued> + <InterestPaid>9279700</InterestPaid> + <PrincipalPaid>14611600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1377338200</PrincipalBalance> + <TotalBalance>1377338200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9182300</InterestAccrued> + <InterestPaid>9182300</InterestPaid> + <PrincipalPaid>14709000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1362629200</PrincipalBalance> + <TotalBalance>1362629200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>9084200</InterestAccrued> + <InterestPaid>9084200</InterestPaid> + <PrincipalPaid>14807100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1347822100</PrincipalBalance> + <TotalBalance>1347822100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8985500</InterestAccrued> + <InterestPaid>8985500</InterestPaid> + <PrincipalPaid>14905800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1332916300</PrincipalBalance> + <TotalBalance>1332916300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8886100</InterestAccrued> + <InterestPaid>8886100</InterestPaid> + <PrincipalPaid>15005200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1317911100</PrincipalBalance> + <TotalBalance>1317911100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8786100</InterestAccrued> + <InterestPaid>8786100</InterestPaid> + <PrincipalPaid>15105200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1302805900</PrincipalBalance> + <TotalBalance>1302805900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8685400</InterestAccrued> + <InterestPaid>8685400</InterestPaid> + <PrincipalPaid>15205900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1287600000</PrincipalBalance> + <TotalBalance>1287600000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8584000</InterestAccrued> + <InterestPaid>8584000</InterestPaid> + <PrincipalPaid>15307300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1272292700</PrincipalBalance> + <TotalBalance>1272292700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2016</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8482000</InterestAccrued> + <InterestPaid>8482000</InterestPaid> + <PrincipalPaid>15409300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1256883400</PrincipalBalance> + <TotalBalance>1256883400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2016</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>108372300</InterestAccrued> + <InterestPaid>108372300</InterestPaid> + <PrincipalPaid>178323300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1256883400</PrincipalBalance> + <TotalBalance>1256883400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8379200</InterestAccrued> + <InterestPaid>8379200</InterestPaid> + <PrincipalPaid>15512100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1241371300</PrincipalBalance> + <TotalBalance>1241371300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8275800</InterestAccrued> + <InterestPaid>8275800</InterestPaid> + <PrincipalPaid>15615500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1225755800</PrincipalBalance> + <TotalBalance>1225755800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8171700</InterestAccrued> + <InterestPaid>8171700</InterestPaid> + <PrincipalPaid>15719600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1210036200</PrincipalBalance> + <TotalBalance>1210036200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>8066900</InterestAccrued> + <InterestPaid>8066900</InterestPaid> + <PrincipalPaid>15824400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1194211800</PrincipalBalance> + <TotalBalance>1194211800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7961400</InterestAccrued> + <InterestPaid>7961400</InterestPaid> + <PrincipalPaid>15929900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1178281900</PrincipalBalance> + <TotalBalance>1178281900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7855200</InterestAccrued> + <InterestPaid>7855200</InterestPaid> + <PrincipalPaid>16036100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1162245800</PrincipalBalance> + <TotalBalance>1162245800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7748300</InterestAccrued> + <InterestPaid>7748300</InterestPaid> + <PrincipalPaid>16143000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1146102800</PrincipalBalance> + <TotalBalance>1146102800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7640700</InterestAccrued> + <InterestPaid>7640700</InterestPaid> + <PrincipalPaid>16250600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1129852200</PrincipalBalance> + <TotalBalance>1129852200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7532300</InterestAccrued> + <InterestPaid>7532300</InterestPaid> + <PrincipalPaid>16359000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1113493200</PrincipalBalance> + <TotalBalance>1113493200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7423300</InterestAccrued> + <InterestPaid>7423300</InterestPaid> + <PrincipalPaid>16468000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1097025200</PrincipalBalance> + <TotalBalance>1097025200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7313500</InterestAccrued> + <InterestPaid>7313500</InterestPaid> + <PrincipalPaid>16577800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1080447400</PrincipalBalance> + <TotalBalance>1080447400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2017</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7203000</InterestAccrued> + <InterestPaid>7203000</InterestPaid> + <PrincipalPaid>16688300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1063759100</PrincipalBalance> + <TotalBalance>1063759100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2017</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>93571300</InterestAccrued> + <InterestPaid>93571300</InterestPaid> + <PrincipalPaid>193124300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1063759100</PrincipalBalance> + <TotalBalance>1063759100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>7091700</InterestAccrued> + <InterestPaid>7091700</InterestPaid> + <PrincipalPaid>16799600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1046959500</PrincipalBalance> + <TotalBalance>1046959500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6979700</InterestAccrued> + <InterestPaid>6979700</InterestPaid> + <PrincipalPaid>16911600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1030047900</PrincipalBalance> + <TotalBalance>1030047900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6867000</InterestAccrued> + <InterestPaid>6867000</InterestPaid> + <PrincipalPaid>17024300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>1013023600</PrincipalBalance> + <TotalBalance>1013023600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6753500</InterestAccrued> + <InterestPaid>6753500</InterestPaid> + <PrincipalPaid>17137800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>995885800</PrincipalBalance> + <TotalBalance>995885800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6639200</InterestAccrued> + <InterestPaid>6639200</InterestPaid> + <PrincipalPaid>17252100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>978633700</PrincipalBalance> + <TotalBalance>978633700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6524200</InterestAccrued> + <InterestPaid>6524200</InterestPaid> + <PrincipalPaid>17367100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>961266600</PrincipalBalance> + <TotalBalance>961266600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6408400</InterestAccrued> + <InterestPaid>6408400</InterestPaid> + <PrincipalPaid>17482900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>943783700</PrincipalBalance> + <TotalBalance>943783700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6291900</InterestAccrued> + <InterestPaid>6291900</InterestPaid> + <PrincipalPaid>17599400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>926184300</PrincipalBalance> + <TotalBalance>926184300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6174600</InterestAccrued> + <InterestPaid>6174600</InterestPaid> + <PrincipalPaid>17716700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>908467600</PrincipalBalance> + <TotalBalance>908467600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>6056500</InterestAccrued> + <InterestPaid>6056500</InterestPaid> + <PrincipalPaid>17834800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>890632800</PrincipalBalance> + <TotalBalance>890632800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5937600</InterestAccrued> + <InterestPaid>5937600</InterestPaid> + <PrincipalPaid>17953700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>872679100</PrincipalBalance> + <TotalBalance>872679100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2018</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5817900</InterestAccrued> + <InterestPaid>5817900</InterestPaid> + <PrincipalPaid>18073400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>854605700</PrincipalBalance> + <TotalBalance>854605700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2018</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>77542200</InterestAccrued> + <InterestPaid>77542200</InterestPaid> + <PrincipalPaid>209153400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>854605700</PrincipalBalance> + <TotalBalance>854605700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5697400</InterestAccrued> + <InterestPaid>5697400</InterestPaid> + <PrincipalPaid>18193900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>836411800</PrincipalBalance> + <TotalBalance>836411800</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5576100</InterestAccrued> + <InterestPaid>5576100</InterestPaid> + <PrincipalPaid>18315200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>818096600</PrincipalBalance> + <TotalBalance>818096600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5454000</InterestAccrued> + <InterestPaid>5454000</InterestPaid> + <PrincipalPaid>18437300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>799659300</PrincipalBalance> + <TotalBalance>799659300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5331100</InterestAccrued> + <InterestPaid>5331100</InterestPaid> + <PrincipalPaid>18560200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>781099100</PrincipalBalance> + <TotalBalance>781099100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5207300</InterestAccrued> + <InterestPaid>5207300</InterestPaid> + <PrincipalPaid>18684000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>762415100</PrincipalBalance> + <TotalBalance>762415100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>5082800</InterestAccrued> + <InterestPaid>5082800</InterestPaid> + <PrincipalPaid>18808500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>743606600</PrincipalBalance> + <TotalBalance>743606600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4957400</InterestAccrued> + <InterestPaid>4957400</InterestPaid> + <PrincipalPaid>18933900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>724672700</PrincipalBalance> + <TotalBalance>724672700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4831200</InterestAccrued> + <InterestPaid>4831200</InterestPaid> + <PrincipalPaid>19060100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>705612600</PrincipalBalance> + <TotalBalance>705612600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4704100</InterestAccrued> + <InterestPaid>4704100</InterestPaid> + <PrincipalPaid>19187200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>686425400</PrincipalBalance> + <TotalBalance>686425400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4576200</InterestAccrued> + <InterestPaid>4576200</InterestPaid> + <PrincipalPaid>19315100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>667110300</PrincipalBalance> + <TotalBalance>667110300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4447400</InterestAccrued> + <InterestPaid>4447400</InterestPaid> + <PrincipalPaid>19443900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>647666400</PrincipalBalance> + <TotalBalance>647666400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2019</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4317800</InterestAccrued> + <InterestPaid>4317800</InterestPaid> + <PrincipalPaid>19573500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>628092900</PrincipalBalance> + <TotalBalance>628092900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2019</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>60182800</InterestAccrued> + <InterestPaid>60182800</InterestPaid> + <PrincipalPaid>226512800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>628092900</PrincipalBalance> + <TotalBalance>628092900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4187300</InterestAccrued> + <InterestPaid>4187300</InterestPaid> + <PrincipalPaid>19704000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>608388900</PrincipalBalance> + <TotalBalance>608388900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>4055900</InterestAccrued> + <InterestPaid>4055900</InterestPaid> + <PrincipalPaid>19835400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>588553500</PrincipalBalance> + <TotalBalance>588553500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3923700</InterestAccrued> + <InterestPaid>3923700</InterestPaid> + <PrincipalPaid>19967600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>568585900</PrincipalBalance> + <TotalBalance>568585900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3790600</InterestAccrued> + <InterestPaid>3790600</InterestPaid> + <PrincipalPaid>20100700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>548485200</PrincipalBalance> + <TotalBalance>548485200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3656600</InterestAccrued> + <InterestPaid>3656600</InterestPaid> + <PrincipalPaid>20234700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>528250500</PrincipalBalance> + <TotalBalance>528250500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3521700</InterestAccrued> + <InterestPaid>3521700</InterestPaid> + <PrincipalPaid>20369600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>507880900</PrincipalBalance> + <TotalBalance>507880900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3385900</InterestAccrued> + <InterestPaid>3385900</InterestPaid> + <PrincipalPaid>20505400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>487375500</PrincipalBalance> + <TotalBalance>487375500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3249200</InterestAccrued> + <InterestPaid>3249200</InterestPaid> + <PrincipalPaid>20642100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>466733400</PrincipalBalance> + <TotalBalance>466733400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>3111600</InterestAccrued> + <InterestPaid>3111600</InterestPaid> + <PrincipalPaid>20779700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>445953700</PrincipalBalance> + <TotalBalance>445953700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2973000</InterestAccrued> + <InterestPaid>2973000</InterestPaid> + <PrincipalPaid>20918300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>425035400</PrincipalBalance> + <TotalBalance>425035400</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2833600</InterestAccrued> + <InterestPaid>2833600</InterestPaid> + <PrincipalPaid>21057700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>403977700</PrincipalBalance> + <TotalBalance>403977700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2020</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2693200</InterestAccrued> + <InterestPaid>2693200</InterestPaid> + <PrincipalPaid>21198100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>382779600</PrincipalBalance> + <TotalBalance>382779600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2020</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>41382300</InterestAccrued> + <InterestPaid>41382300</InterestPaid> + <PrincipalPaid>245313300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>382779600</PrincipalBalance> + <TotalBalance>382779600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2551900</InterestAccrued> + <InterestPaid>2551900</InterestPaid> + <PrincipalPaid>21339400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>361440200</PrincipalBalance> + <TotalBalance>361440200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2409600</InterestAccrued> + <InterestPaid>2409600</InterestPaid> + <PrincipalPaid>21481700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>339958500</PrincipalBalance> + <TotalBalance>339958500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2266400</InterestAccrued> + <InterestPaid>2266400</InterestPaid> + <PrincipalPaid>21624900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>318333600</PrincipalBalance> + <TotalBalance>318333600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>2122200</InterestAccrued> + <InterestPaid>2122200</InterestPaid> + <PrincipalPaid>21769100</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>296564500</PrincipalBalance> + <TotalBalance>296564500</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1977100</InterestAccrued> + <InterestPaid>1977100</InterestPaid> + <PrincipalPaid>21914200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>274650300</PrincipalBalance> + <TotalBalance>274650300</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>06/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1831000</InterestAccrued> + <InterestPaid>1831000</InterestPaid> + <PrincipalPaid>22060300</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>252590000</PrincipalBalance> + <TotalBalance>252590000</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>07/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1683900</InterestAccrued> + <InterestPaid>1683900</InterestPaid> + <PrincipalPaid>22207400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>230382600</PrincipalBalance> + <TotalBalance>230382600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>08/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1535900</InterestAccrued> + <InterestPaid>1535900</InterestPaid> + <PrincipalPaid>22355400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>208027200</PrincipalBalance> + <TotalBalance>208027200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>09/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1386800</InterestAccrued> + <InterestPaid>1386800</InterestPaid> + <PrincipalPaid>22504500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>185522700</PrincipalBalance> + <TotalBalance>185522700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>10/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1236800</InterestAccrued> + <InterestPaid>1236800</InterestPaid> + <PrincipalPaid>22654500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>162868200</PrincipalBalance> + <TotalBalance>162868200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>11/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>1085800</InterestAccrued> + <InterestPaid>1085800</InterestPaid> + <PrincipalPaid>22805500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>140062700</PrincipalBalance> + <TotalBalance>140062700</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>12/08/2021</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>933800</InterestAccrued> + <InterestPaid>933800</InterestPaid> + <PrincipalPaid>22957500</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>117105200</PrincipalBalance> + <TotalBalance>117105200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2021</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>286695600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>21021200</InterestAccrued> + <InterestPaid>21021200</InterestPaid> + <PrincipalPaid>265674400</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>117105200</PrincipalBalance> + <TotalBalance>117105200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>01/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>780700</InterestAccrued> + <InterestPaid>780700</InterestPaid> + <PrincipalPaid>23110600</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>93994600</PrincipalBalance> + <TotalBalance>93994600</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>02/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>626600</InterestAccrued> + <InterestPaid>626600</InterestPaid> + <PrincipalPaid>23264700</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>70729900</PrincipalBalance> + <TotalBalance>70729900</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>03/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>471500</InterestAccrued> + <InterestPaid>471500</InterestPaid> + <PrincipalPaid>23419800</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>47310100</PrincipalBalance> + <TotalBalance>47310100</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>04/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23891300</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>315400</InterestAccrued> + <InterestPaid>315400</InterestPaid> + <PrincipalPaid>23575900</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>23734200</PrincipalBalance> + <TotalBalance>23734200</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>9</AmortizationLineType> + <Date>05/08/2022</Date> + <Loan1Amount></Loan1Amount> + <Loan2Amount></Loan2Amount> + <Loan3Amount></Loan3Amount> + <Payment1Amount>23892400</Payment1Amount> + <Payment2Amount></Payment2Amount> + <Payment3Amount></Payment3Amount> + <InterestAccrued>158200</InterestAccrued> + <InterestPaid>158200</InterestPaid> + <PrincipalPaid>23734200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>0</PrincipalBalance> + <TotalBalance>0</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>51</AmortizationLineType> + <Date>12/31/2022</Date> + <Loan1Amount>0</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>119457600</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>2352400</InterestAccrued> + <InterestPaid>2352400</InterestPaid> + <PrincipalPaid>117105200</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>0</PrincipalBalance> + <TotalBalance>0</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> + <AmortizationLine> + <AmortizationLineType>52</AmortizationLineType> + <Date>05/31/2022</Date> + <Loan1Amount>2500000000</Loan1Amount> + <Loan2Amount>0</Loan2Amount> + <Loan3Amount>0</Loan3Amount> + <Payment1Amount>4300435100</Payment1Amount> + <Payment2Amount>0</Payment2Amount> + <Payment3Amount>0</Payment3Amount> + <InterestAccrued>1800435100</InterestAccrued> + <InterestPaid>1800435100</InterestPaid> + <PrincipalPaid>2500000000</PrincipalPaid> + <UnpaidInterestBalance>0</UnpaidInterestBalance> + <PrincipalBalance>0</PrincipalBalance> + <TotalBalance>0</TotalBalance> + <RateChangeRate></RateChangeRate> + <RateChangeCompounding>13</RateChangeCompounding> + </AmortizationLine> +</TValueAmortizationSchedule> + \ No newline at end of file diff --git a/test/test_helper.rb b/test/test_helper.rb index a1ac9d5..f35bbd2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,37 +1,38 @@ $:.unshift(File.dirname(__FILE__) + "/../lib/") require 'test/unit' require 'stater' require 'rubygems' require 'hpricot' class Test::Unit::TestCase def assert_schedule(xml_file, schedule) control_schedule = [] doc = Hpricot(open(xml_file)) lines = (doc/:tvalueamortizationschedule/:amortizationline) lines.each do |line| if line.search(:amortizationlinetype).innerHTML == '9' - payment = line.search(:payment1amount).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') - interest_paid = line.search(:interestpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') - principal_paid = line.search(:principalpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + payment = line.search(:payment1amount).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + interest_paid = line.search(:interestpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + principal_paid = line.search(:principalpaid).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') principal_balance = line.search(:principalbalance).innerHTML.gsub(/(\d{2})\d{2}$/, '.\1') + control_schedule << Struct::Payment.new(nil, payment, principal_paid, interest_paid, principal_balance) end end # assert_equal control_schedule.size, schedule.size, "The number of amortization lines is not the same." schedule.each_with_index do |line, index| assert_equal control_schedule[index].payment, line.payment.to_s('F').gsub(/\.(\d{1})$/, '.\10').gsub(/^0/, ''), "payment at amortization line: #{index}" assert_equal control_schedule[index].interest_paid, line.interest_paid.to_s('F').gsub(/\.(\d{1})$/, '.\10').gsub(/^0/, ''), "interest at amortization line #{index}" assert_equal control_schedule[index].principal_paid, line.principal_paid.to_s('F').gsub(/\.(\d{1})$/, '.\10').gsub(/^0/, ''), "principal at amortization line #{index}" assert_equal control_schedule[index].principal_balance, line.principal_balance.to_s('F').gsub(/\.(\d{1})$/, '.\10').gsub(/^0/, ''), "principal_balance at amortization line #{index}" end end end diff --git a/test/unit/amortization_test.rb b/test/unit/amortization_test.rb index 6bf038f..b0c5fc6 100644 --- a/test/unit/amortization_test.rb +++ b/test/unit/amortization_test.rb @@ -1,44 +1,44 @@ require File.dirname(__FILE__) + '/../test_helper' class Stater::AmortizationTest < Test::Unit::TestCase def test_new_amortization amortization = Stater::Amortization.new assert_equal [], amortization.schedule assert_nil amortization.principal assert_nil amortization.periodic_rate assert_nil amortization.periods end def test_payment principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 amortization = Stater::Amortization.new(250000.00, periodic_rate, periods) assert_kind_of BigDecimal, amortization.calculate_payment assert_equal BigDecimal('2389.13'), amortization.calculate_payment end def test_schedule principal = 250000.00 periodic_rate = 0.08 / 12 periods = 15 * 12 amortization = Stater::Amortization.new(principal, periodic_rate, periods) assert_kind_of BigDecimal, amortization.principal assert_equal BigDecimal(principal.to_s), amortization.principal assert_kind_of BigDecimal, amortization.periodic_rate assert_equal BigDecimal(periodic_rate.to_s), amortization.periodic_rate assert_kind_of Fixnum, amortization.periods assert_equal periods, amortization.periods # Compare to TValue schedules - they should match exactly - assert_schedule('./../fixtures/FEC_example_3_3_1.xml', amortization.schedule) + assert_schedule(File.dirname(__FILE__) + "/../fixtures/FEC_example_3_3_1.xml", amortization.schedule) end end \ No newline at end of file diff --git a/test/unit/tvm_test.rb b/test/unit/tvm_test.rb index ec656d6..5949f2d 100644 --- a/test/unit/tvm_test.rb +++ b/test/unit/tvm_test.rb @@ -1,45 +1,45 @@ require File.dirname(__FILE__) + '/../test_helper' class Stater::TVMTest < Test::Unit::TestCase def test_future_value present_value = 6000.00 periodic_rate = 0.04 / 12 periods = 84 - assert_equal '7935.08318331367', Stater::TVM.fv(present_value, periodic_rate, periods).to_s + assert_equal '7935.08318331367', Stater::TVM.fv(present_value, 0.04, 7, 12).to_s end def test_present_value future_value = 7935.08 periodic_rate = 0.04 / 12 periods = 84 - assert_equal '5999.99759298276', Stater::TVM.pv(future_value, periodic_rate, periods).to_s + assert_equal '5999.99759298276', Stater::TVM.pv(future_value, 0.04, 7, 12).to_s end def test_interest assert_equal '0.039999942499020946229393302929', sprintf('%3.30f', Stater::TVM.interest(6000.0, 7935.08, 7, 12)) end def test_years assert_equal '6.99998995405338', Stater::TVM.years(6000.0, 7935.08, 0.04, 12).to_s end def test_interest_to_apr assert_equal '0.195618171461533', Stater::TVM.i_to_apr(0.18, 12).to_s end def test_apr_to_interest assert_equal '0.179999854440594', Stater::TVM.apr_to_i(0.195618, 12).to_s end def test_apr_to_ear assert_equal '0.137919903125943', Stater::TVM.apr_to_ear(0.1299, 12).to_s end def test_ear_to_apr assert_equal '0.129900000000001', Stater::TVM.ear_to_apr(0.137919903125943, 12).to_s end end \ No newline at end of file