white_horseman 1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Battleship.Rakefile +12 -0
- data/Rakefile +47 -0
- data/lib/white_horseman/analyst.rb +63 -0
- data/lib/white_horseman/battlefield.rb +64 -0
- data/lib/white_horseman/captain.rb +58 -0
- data/lib/white_horseman/cell_status.rb +45 -0
- data/lib/white_horseman/coordinates.rb +87 -0
- data/lib/white_horseman/fleet_admiral.rb +79 -0
- data/lib/white_horseman/opponent.rb +70 -0
- data/lib/white_horseman/placement.rb +97 -0
- data/lib/white_horseman/scout.rb +66 -0
- data/lib/white_horseman/ship.rb +45 -0
- data/lib/white_horseman/white_horseman.rb +187 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/white_horseman/analyst_spec.rb +52 -0
- data/spec/white_horseman/battlefield_spec.rb +121 -0
- data/spec/white_horseman/captain_spec.rb +57 -0
- data/spec/white_horseman/cell_status_spec.rb +37 -0
- data/spec/white_horseman/coordinates_spec.rb +171 -0
- data/spec/white_horseman/fleet_admiral_spec.rb +54 -0
- data/spec/white_horseman/opponent_spec.rb +58 -0
- data/spec/white_horseman/placement_spec.rb +111 -0
- data/spec/white_horseman/scout_spec.rb +85 -0
- data/spec/white_horseman/ship_spec.rb +44 -0
- data/spec/white_horseman/white_horesman_integration_spec.rb +22 -0
- data/spec/white_horseman/white_horseman_spec.rb +97 -0
- data/test_data/testman.data +104 -0
- metadata +85 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'white_horseman/fleet_admiral'
|
3
|
+
require 'white_horseman/battlefield'
|
4
|
+
|
5
|
+
describe WhiteHorseman::FleetAdmiral do
|
6
|
+
before(:each) do
|
7
|
+
@ship_placement = WhiteHorseman::FleetAdmiral.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise error if calculate hasn't been called" do
|
11
|
+
lambda{@ship_placement.destroyer}.should raise_error("Call calculate first")
|
12
|
+
lambda{@ship_placement.battleship}.should raise_error("Call calculate first")
|
13
|
+
lambda{@ship_placement.submarine}.should raise_error("Call calculate first")
|
14
|
+
lambda{@ship_placement.carrier}.should raise_error("Call calculate first")
|
15
|
+
lambda{@ship_placement.patrolship}.should raise_error("Call calculate first")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should place all ships" do
|
19
|
+
@ship_placement.heat_map = WhiteHorseman::Battlefield.new([
|
20
|
+
# 1 2 3 4 5 6 7 8 9 10
|
21
|
+
[100,100,100,100,100,100, 10, 10, 10, 10], # A
|
22
|
+
[100,100,100,100, 0, 0, 0, 0, 0,100], # B
|
23
|
+
[100,100,100,100,100,100,100,100,100,100], # C
|
24
|
+
[100,100,100,100,100,100,100,100,100,100], # D
|
25
|
+
[100,100,100,100, 30,100,100,100,100,100], # E
|
26
|
+
[ 15,100,100,100, 30,100,100,100,100,100], # F
|
27
|
+
[ 15,100,100,100,100,100,100,100,100,100], # G
|
28
|
+
[ 15,100,100,100,100,100,100, 20,100,100], # H
|
29
|
+
[100,100,100,100,100,100,100, 20,100,100], # I
|
30
|
+
[100,100,100,100,100,100,100, 20,100,100], # J
|
31
|
+
])
|
32
|
+
|
33
|
+
@ship_placement.calculate
|
34
|
+
@ship_placement.carrier.should == "B5 horizontal"
|
35
|
+
@ship_placement.carrier.should == "B5 horizontal"
|
36
|
+
@ship_placement.battleship.should == "A7 horizontal"
|
37
|
+
|
38
|
+
["F1 vertical", "H8 vertical"].should include(@ship_placement.submarine)
|
39
|
+
["F1 vertical", "H8 vertical"].should include(@ship_placement.destroyer)
|
40
|
+
@ship_placement.patrolship.should == "E5 vertical"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should randomize placement when there are multiple equal options" do
|
44
|
+
map = WhiteHorseman::Battlefield.new
|
45
|
+
map.set_all(0.0)
|
46
|
+
@ship_placement.heat_map = map
|
47
|
+
@ship_placement.calculate
|
48
|
+
first_carrier = @ship_placement.carrier
|
49
|
+
|
50
|
+
@ship_placement.calculate
|
51
|
+
@ship_placement.carrier.should_not == first_carrier
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
require 'white_horseman/opponent'
|
4
|
+
describe WhiteHorseman::Opponent do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
WhiteHorseman::Opponent.clear_all
|
8
|
+
@opponent = WhiteHorseman::Opponent.new("dr_evil")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have name" do
|
12
|
+
@opponent.name.should == "dr_evil"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should create a new game" do
|
16
|
+
id = @opponent.new_game
|
17
|
+
id.should == 1
|
18
|
+
@opponent.number_of_games.should == 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create multiple games" do
|
22
|
+
@opponent.new_game.should_not == @opponent.new_game
|
23
|
+
@opponent.number_of_games.should == 2
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should grids for multiple games" do
|
27
|
+
mockfield = mock("Battlefield")
|
28
|
+
WhiteHorseman::Battlefield.should_receive(:new).and_return(mockfield)
|
29
|
+
mockfield.should_receive(:record_target).with("J10")
|
30
|
+
id = @opponent.new_game
|
31
|
+
@opponent.record_target("J10")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should save the game" do
|
35
|
+
@opponent.new_game
|
36
|
+
@opponent.save
|
37
|
+
|
38
|
+
loaded = WhiteHorseman::Opponent.new("dr_evil")
|
39
|
+
loaded.number_of_games.should == 1
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have heat map" do
|
43
|
+
mockfield1 = mock("Battlefield1")
|
44
|
+
mockfield2 = mock("Battlefield2")
|
45
|
+
mockfield3 = mock("Battlefield3")
|
46
|
+
WhiteHorseman::Battlefield.should_receive(:new).exactly(3).and_return(mockfield1, mockfield2, mockfield3)
|
47
|
+
3.times {@opponent.new_game}
|
48
|
+
average_field = mock("Battlefield ave")
|
49
|
+
WhiteHorseman::Battlefield.should_receive(:average).with([mockfield1, mockfield2, mockfield3]).and_return(average_field)
|
50
|
+
|
51
|
+
@opponent.heat_map.should == average_field
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should zeroed heat map when there are no games" do
|
55
|
+
@opponent.heat_map["A1"].should == 0
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'white_horseman/placement'
|
3
|
+
require 'white_horseman/battlefield'
|
4
|
+
|
5
|
+
describe WhiteHorseman::Placement do
|
6
|
+
before(:each) do
|
7
|
+
@placement = WhiteHorseman::Placement.new(:row => "A", :column => 1, :orientation => :horizontal, :size => 5)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should print" do
|
11
|
+
@placement.to_s.should == "A1 horizontal"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have readers" do
|
15
|
+
@placement.row.should == "A"
|
16
|
+
@placement.column.should == 1
|
17
|
+
@placement.orientation.should == :horizontal
|
18
|
+
@placement.size.should == 5
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be valid" do
|
22
|
+
WhiteHorseman::Placement.new(:row => "A",:column => 1, :orientation => :vertical, :size => 5).should be_valid
|
23
|
+
WhiteHorseman::Placement.new(:row => "A",:column => 7, :orientation => :vertical, :size => 5).should be_valid
|
24
|
+
WhiteHorseman::Placement.new(:row => "A",:column => 7, :orientation => :horizontal, :size => 4).should be_valid
|
25
|
+
WhiteHorseman::Placement.new(:row => "H",:column => 1, :orientation => :horizontal, :size => 5).should be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be invalid" do
|
29
|
+
WhiteHorseman::Placement.new(:row => "G",:column => 1, :orientation => :vertical, :size => 5).should_not be_valid
|
30
|
+
WhiteHorseman::Placement.new(:row => "A",:column => 7, :orientation => :horizontal, :size => 5).should_not be_valid
|
31
|
+
WhiteHorseman::Placement.new(:row => "H",:column => 1, :orientation => "bleck", :size => 5).should_not be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should overlap" do
|
35
|
+
@placement = WhiteHorseman::Placement.new(:row => "C", :column => 1, :orientation => :horizontal, :size => 5)
|
36
|
+
@placement2 = WhiteHorseman::Placement.new(:row => "A", :column => 3, :orientation => :vertical, :size => 4)
|
37
|
+
|
38
|
+
@placement.should be_overlap(@placement2)
|
39
|
+
@placement2.should be_overlap(@placement)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have cells" do
|
43
|
+
@placement.cells.should == ["A1", "A2", "A3", "A4", "A5"]
|
44
|
+
WhiteHorseman::Placement.new(:row => "A", :column => 3, :orientation => :vertical, :size => 4).cells.should == ["A3", "B3", "C3", "D3"]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not overlap" do
|
48
|
+
@placement = WhiteHorseman::Placement.new(:row => "C", :column => 1, :orientation => :horizontal, :size => 5)
|
49
|
+
@placement2 = WhiteHorseman::Placement.new(:row => "D", :column => 3, :orientation => :vertical, :size => 4)
|
50
|
+
|
51
|
+
@placement.should_not be_overlap(@placement2)
|
52
|
+
@placement2.should_not be_overlap(@placement)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should initialize with coordinates" do
|
56
|
+
coord = WhiteHorseman::Coordinates.new(:row => "G", :column => 6)
|
57
|
+
@placement = WhiteHorseman::Placement.new(:coord => coord, :orientation => :horizontal, :size => 5)
|
58
|
+
@placement.row.should == "G"
|
59
|
+
@placement.column.should == 6
|
60
|
+
@placement.coord.should == coord
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should include coordinates" do
|
64
|
+
@placement.should include("A1")
|
65
|
+
@placement.should include("A2".to_coord)
|
66
|
+
@placement.should include("A5".to_coord)
|
67
|
+
@placement.should_not include("B1")
|
68
|
+
@placement.should_not include("A7".to_coord)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should not increment beyond bounds on horizontal include" do
|
72
|
+
@placement = WhiteHorseman::Placement.new(:row => "A", :column => 6 , :orientation => :horizontal, :size => 5)
|
73
|
+
@placement.should be_valid
|
74
|
+
@placement.should include("A6")
|
75
|
+
@placement.should include("A7")
|
76
|
+
@placement.should include("A8")
|
77
|
+
@placement.should include("A9")
|
78
|
+
@placement.should include("A10")
|
79
|
+
lambda{@placement.should include("A11")}.should raise_error
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should not increment beyond bounds on vertical include" do
|
83
|
+
place = WhiteHorseman::Placement.new(:row => "F", :column => 6 , :orientation => :vertical, :size => 5)
|
84
|
+
place.should be_valid
|
85
|
+
|
86
|
+
place.should include("F6")
|
87
|
+
place.row.should == "F"
|
88
|
+
|
89
|
+
place.should include("G6")
|
90
|
+
place.should include("H6")
|
91
|
+
place.should include("I6")
|
92
|
+
place.should include("J6")
|
93
|
+
lambda{@placement.should include("K6")}.should raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should keep its own copy of coordinate" do
|
97
|
+
coordinates = WhiteHorseman::Coordinates.new(:row => "A", :column => 3)
|
98
|
+
place = WhiteHorseman::Placement.new(:coord => coordinates , :orientation => :vertical, :size => 5)
|
99
|
+
coordinates.row = "C"
|
100
|
+
place.row.should == "A"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should do each placement" do
|
104
|
+
num = 0
|
105
|
+
WhiteHorseman::Placement.each(5) do |placement|
|
106
|
+
placement.should be_valid
|
107
|
+
num += 1
|
108
|
+
end
|
109
|
+
num.should == 120
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'white_horseman/scout'
|
3
|
+
require 'white_horseman/battlefield'
|
4
|
+
require "white_horseman/cell_status"
|
5
|
+
|
6
|
+
describe WhiteHorseman::Scout do
|
7
|
+
before(:each) do
|
8
|
+
@scout = WhiteHorseman::Scout.new
|
9
|
+
@hit_board = WhiteHorseman::Battlefield.new
|
10
|
+
@hit_board.set_all(WhiteHorseman::CellStatus.new)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should calculate possible placements" do
|
14
|
+
@scout.possible_placements(2, ["F5"], @hit_board).should == 4
|
15
|
+
@scout.possible_placements(3, ["F5"], @hit_board).should == 6
|
16
|
+
@scout.possible_placements(4, ["F5"], @hit_board).should == 8
|
17
|
+
@scout.possible_placements(5, ["F5"], @hit_board).should == 10
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have no possible placements if coords aren't colinear" do
|
21
|
+
@scout.possible_placements(2, ["F5", "G7"], @hit_board).should == 0
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should calculate possible placements for multiple cells" do
|
25
|
+
@scout.possible_placements(2, ["F5", "F6"], @hit_board).should == 1
|
26
|
+
@scout.possible_placements(3, ["F5", "F6"], @hit_board).should == 2
|
27
|
+
@scout.possible_placements(4, ["F5", "F6"], @hit_board).should == 3
|
28
|
+
@scout.possible_placements(5, ["F6", "F7"], @hit_board).should == 4
|
29
|
+
|
30
|
+
@scout.possible_placements(2, ["F5", "G5"], @hit_board).should == 1
|
31
|
+
@scout.possible_placements(3, ["F5", "G5"], @hit_board).should == 2
|
32
|
+
@scout.possible_placements(4, ["F5", "G5"], @hit_board).should == 3
|
33
|
+
@scout.possible_placements(5, ["F5", "G5"], @hit_board).should == 4
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should calculate possible placements for cells with gaps" do
|
37
|
+
@scout.possible_placements(2, ["F5", "F7"], @hit_board).should == 0
|
38
|
+
@scout.possible_placements(3, ["F5", "F7"], @hit_board).should == 1
|
39
|
+
@scout.possible_placements(4, ["F5", "F7"], @hit_board).should == 2
|
40
|
+
@scout.possible_placements(5, ["F5", "H5"], @hit_board).should == 3
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should exclude placements containing misses from possible placements" do
|
44
|
+
@hit_board["F6"] = WhiteHorseman::CellStatus.new(false)
|
45
|
+
@scout.possible_placements(2, ["F5"], @hit_board).should == 3
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should excule placements that would leave the battlefield" do
|
49
|
+
@scout.possible_placements(5, ["A1"], @hit_board).should == 2
|
50
|
+
@scout.possible_placements(5, ["J10"], @hit_board).should == 2
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be boxed in" do
|
54
|
+
@hit_board["G4"] = WhiteHorseman::CellStatus.new(false)
|
55
|
+
@hit_board["F5"] = WhiteHorseman::CellStatus.new(false)
|
56
|
+
@hit_board["G6"] = WhiteHorseman::CellStatus.new(false)
|
57
|
+
@scout.possible_placements(2, ["G5"], @hit_board).should == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have possible placements for sunken ships" do
|
61
|
+
@hit_board["G4"] = WhiteHorseman::CellStatus.new(true)
|
62
|
+
@hit_board["G5"] = WhiteHorseman::CellStatus.new(true)
|
63
|
+
@hit_board["G6"] = WhiteHorseman::CellStatus.new(true)
|
64
|
+
@hit_board["G7"] = WhiteHorseman::CellStatus.new(true)
|
65
|
+
|
66
|
+
|
67
|
+
placements = @scout.salvage_placements(4, "G5", @hit_board)
|
68
|
+
placements.size.should == 1
|
69
|
+
placements[0].should include("G4")
|
70
|
+
placements[0].should include("G5")
|
71
|
+
placements[0].should include("G6")
|
72
|
+
placements[0].should include("G7")
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should exclude placements containing hits from sunken ships" do
|
76
|
+
@hit_board["E6"] = WhiteHorseman::CellStatus.new(true)
|
77
|
+
@hit_board["E6"].ship = :patrolship
|
78
|
+
@hit_board["F6"] = WhiteHorseman::CellStatus.new(true)
|
79
|
+
@hit_board["F6"].ship = :patrolship
|
80
|
+
|
81
|
+
@scout.possible_placements(2, ["F5"], @hit_board).should == 3
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
require 'white_horseman/ship'
|
3
|
+
|
4
|
+
describe WhiteHorseman::Ship do
|
5
|
+
it "should have symbol and size" do
|
6
|
+
ship = WhiteHorseman::Ship.new(:battleship)
|
7
|
+
ship.symbol.should == :battleship
|
8
|
+
ship.size.should == 4
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have the correct size for all ships" do
|
12
|
+
ship = WhiteHorseman::Ship.new(:patrolship).size.should == 2
|
13
|
+
ship = WhiteHorseman::Ship.new(:carrier).size.should == 5
|
14
|
+
ship = WhiteHorseman::Ship.new(:submarine).size.should == 3
|
15
|
+
ship = WhiteHorseman::Ship.new(:destroyer).size.should == 3
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have each ship" do
|
19
|
+
ships = []
|
20
|
+
WhiteHorseman::Ship.each do |ship|
|
21
|
+
ships << ship
|
22
|
+
end
|
23
|
+
check_ships(ships)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have all the ships" do
|
27
|
+
ships = WhiteHorseman::Ship.all
|
28
|
+
ships.size.should == 5
|
29
|
+
check_ships(ships)
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_ships(ships)
|
33
|
+
ships.size.should == 5
|
34
|
+
ships[0].symbol.should == :carrier
|
35
|
+
ships[1].symbol.should == :battleship
|
36
|
+
ships[2].symbol.should == :destroyer
|
37
|
+
ships[3].symbol.should == :submarine
|
38
|
+
ships[4].symbol.should == :patrolship
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have equality operator" do
|
42
|
+
WhiteHorseman::Ship.new(:battleship).should == WhiteHorseman::Ship.new(:battleship)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
require 'white_horseman/white_horseman'
|
3
|
+
require 'white_horseman/opponent'
|
4
|
+
|
5
|
+
describe WhiteHorseman::WhiteHorseman, "integration" do
|
6
|
+
it "should work" do
|
7
|
+
WhiteHorseman::Opponent.clear_all
|
8
|
+
@horseman = WhiteHorseman::WhiteHorseman.new
|
9
|
+
@horseman.new_game("testman")
|
10
|
+
|
11
|
+
@horseman.battleship_placement.should_not be_nil
|
12
|
+
@horseman.carrier_placement.should_not be_nil
|
13
|
+
@horseman.submarine_placement.should_not be_nil
|
14
|
+
@horseman.patrolship_placement.should_not be_nil
|
15
|
+
@horseman.destroyer_placement.should_not be_nil
|
16
|
+
|
17
|
+
@horseman.enemy_targeting("A1")
|
18
|
+
|
19
|
+
@horseman.game_over(:victory)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
require 'white_horseman/white_horseman'
|
3
|
+
|
4
|
+
describe WhiteHorseman::WhiteHorseman do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@mock_opponent = mock("opponent", :heat_map => nil, :new_game => nil, :name => "mr_mad")
|
8
|
+
@mock_admiral = mock("fleet admiral", :heat_map= => nil, :calculate => nil)
|
9
|
+
@mock_captain = mock("captain")
|
10
|
+
WhiteHorseman::Opponent.stub!(:new).and_return(@mock_opponent)
|
11
|
+
WhiteHorseman::FleetAdmiral.stub!(:new).and_return(@mock_admiral)
|
12
|
+
WhiteHorseman::Captain.stub!(:new).and_return(@mock_captain)
|
13
|
+
|
14
|
+
lambda { @horseman = WhiteHorseman::WhiteHorseman.new }.should_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create opponent" do
|
18
|
+
WhiteHorseman::Opponent.should_receive(:new).with("mr_mad").and_return(@mock_opponent)
|
19
|
+
|
20
|
+
@horseman.new_game("mr_mad")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not create a new opponent if playing the same person again" do
|
24
|
+
WhiteHorseman::Opponent.should_receive(:new).once.with("mr_mad").and_return(@mock_opponent)
|
25
|
+
|
26
|
+
@horseman.new_game("mr_mad")
|
27
|
+
@horseman.new_game("mr_mad")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should create a new opponent if playing a different person" do
|
31
|
+
WhiteHorseman::Opponent.should_receive(:new).with("mr_mad").and_return(@mock_opponent)
|
32
|
+
WhiteHorseman::Opponent.should_receive(:new).with("new_guy").and_return(@mock_opponent)
|
33
|
+
|
34
|
+
@horseman.new_game("mr_mad")
|
35
|
+
@horseman.new_game("new_guy")
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should start a new game" do
|
39
|
+
@mock_opponent.should_receive(:new_game)
|
40
|
+
|
41
|
+
@horseman.new_game("mr_mad")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should record target" do
|
45
|
+
@horseman.new_game("mr_mad")
|
46
|
+
|
47
|
+
@mock_opponent.should_receive(:record_target).with("A1")
|
48
|
+
|
49
|
+
@horseman.enemy_targeting("A1")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should create an admiral" do
|
53
|
+
WhiteHorseman::FleetAdmiral.should_receive(:new).and_return(@mock_admiral)
|
54
|
+
@horseman.new_game("mr_mad")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should give the opponent's heat map to the admiral" do
|
58
|
+
@heat_map = mock("heat map")
|
59
|
+
@mock_opponent.should_receive(:heat_map).and_return(@heat_map)
|
60
|
+
@mock_admiral.should_receive(:heat_map=).with(@heat_map)
|
61
|
+
|
62
|
+
@horseman.new_game("mr_mad")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should calculate admiral" do
|
66
|
+
@mock_admiral.should_receive(:calculate)
|
67
|
+
|
68
|
+
@horseman.new_game("mr_mad")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should save opponent when game ends" do
|
72
|
+
@opponent.should_receive(:save)
|
73
|
+
|
74
|
+
@horseman.game_over(:victory)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have a plan capitain" do
|
78
|
+
WhiteHorseman::Captain.should_receive(:new).and_return(@mock_captain)
|
79
|
+
|
80
|
+
@horseman.new_game("mr_mad")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should tell the captain about target results" do
|
84
|
+
@mock_captain.should_receive(:target_result).with("G4", true, :battleship)
|
85
|
+
|
86
|
+
@horseman.new_game("mr_mad")
|
87
|
+
@horseman.target_result("G4", true, :battleship)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should ask the capitan for the next target" do
|
91
|
+
@mock_captain.should_receive(:next_target).and_return("I9")
|
92
|
+
|
93
|
+
@horseman.new_game("mr_mad")
|
94
|
+
@horseman.next_target.should == "I9"
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/object:WhiteHorseman::Battlefield
|
3
|
+
grid:
|
4
|
+
- - 99
|
5
|
+
- 0
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
- 0
|
11
|
+
- 0
|
12
|
+
- 0
|
13
|
+
- 0
|
14
|
+
- - 0
|
15
|
+
- 0
|
16
|
+
- 0
|
17
|
+
- 0
|
18
|
+
- 0
|
19
|
+
- 0
|
20
|
+
- 0
|
21
|
+
- 0
|
22
|
+
- 0
|
23
|
+
- 0
|
24
|
+
- - 0
|
25
|
+
- 0
|
26
|
+
- 0
|
27
|
+
- 0
|
28
|
+
- 0
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
- - 0
|
35
|
+
- 0
|
36
|
+
- 0
|
37
|
+
- 0
|
38
|
+
- 0
|
39
|
+
- 0
|
40
|
+
- 0
|
41
|
+
- 0
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
- - 0
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
- 0
|
52
|
+
- 0
|
53
|
+
- 0
|
54
|
+
- - 0
|
55
|
+
- 0
|
56
|
+
- 0
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
- 0
|
60
|
+
- 0
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
- 0
|
64
|
+
- - 0
|
65
|
+
- 0
|
66
|
+
- 0
|
67
|
+
- 0
|
68
|
+
- 0
|
69
|
+
- 0
|
70
|
+
- 0
|
71
|
+
- 0
|
72
|
+
- 0
|
73
|
+
- 0
|
74
|
+
- - 0
|
75
|
+
- 0
|
76
|
+
- 0
|
77
|
+
- 0
|
78
|
+
- 0
|
79
|
+
- 0
|
80
|
+
- 0
|
81
|
+
- 0
|
82
|
+
- 0
|
83
|
+
- 0
|
84
|
+
- - 0
|
85
|
+
- 0
|
86
|
+
- 0
|
87
|
+
- 0
|
88
|
+
- 0
|
89
|
+
- 0
|
90
|
+
- 0
|
91
|
+
- 0
|
92
|
+
- 0
|
93
|
+
- 0
|
94
|
+
- - 0
|
95
|
+
- 0
|
96
|
+
- 0
|
97
|
+
- 0
|
98
|
+
- 0
|
99
|
+
- 0
|
100
|
+
- 0
|
101
|
+
- 0
|
102
|
+
- 0
|
103
|
+
- 0
|
104
|
+
shots: 1
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: white_horseman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.3"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Doug Bradbury
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-12-01 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: The apocalypse is here
|
17
|
+
email: doug@8thlight.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- Battleship.Rakefile
|
26
|
+
- lib
|
27
|
+
- lib/white_horseman
|
28
|
+
- lib/white_horseman/analyst.rb
|
29
|
+
- lib/white_horseman/battlefield.rb
|
30
|
+
- lib/white_horseman/captain.rb
|
31
|
+
- lib/white_horseman/cell_status.rb
|
32
|
+
- lib/white_horseman/coordinates.rb
|
33
|
+
- lib/white_horseman/fleet_admiral.rb
|
34
|
+
- lib/white_horseman/opponent.rb
|
35
|
+
- lib/white_horseman/placement.rb
|
36
|
+
- lib/white_horseman/scout.rb
|
37
|
+
- lib/white_horseman/ship.rb
|
38
|
+
- lib/white_horseman/white_horseman.rb
|
39
|
+
- pkg
|
40
|
+
- Rakefile
|
41
|
+
- spec
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- spec/white_horseman
|
44
|
+
- spec/white_horseman/analyst_spec.rb
|
45
|
+
- spec/white_horseman/battlefield_spec.rb
|
46
|
+
- spec/white_horseman/captain_spec.rb
|
47
|
+
- spec/white_horseman/cell_status_spec.rb
|
48
|
+
- spec/white_horseman/coordinates_spec.rb
|
49
|
+
- spec/white_horseman/fleet_admiral_spec.rb
|
50
|
+
- spec/white_horseman/opponent_spec.rb
|
51
|
+
- spec/white_horseman/placement_spec.rb
|
52
|
+
- spec/white_horseman/scout_spec.rb
|
53
|
+
- spec/white_horseman/ship_spec.rb
|
54
|
+
- spec/white_horseman/white_horesman_integration_spec.rb
|
55
|
+
- spec/white_horseman/white_horseman_spec.rb
|
56
|
+
- test_data
|
57
|
+
- test_data/testman.data
|
58
|
+
has_rdoc: false
|
59
|
+
homepage: http://sparring.rubyforge.org/
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: sparring
|
80
|
+
rubygems_version: 1.2.0
|
81
|
+
signing_key:
|
82
|
+
specification_version: 2
|
83
|
+
summary: Battleship Player:White Horseman
|
84
|
+
test_files: []
|
85
|
+
|