Skip to content

Commit

Permalink
Added DoNothing strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleSucher committed Mar 1, 2012
1 parent 3be3695 commit 2a56fd0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
1 change: 1 addition & 0 deletions greenland-play.rb
Expand Up @@ -4,6 +4,7 @@

game = Game.new
game.create_players
game.name_players

# set player strategies
game.players.each do |player|
Expand Down
3 changes: 2 additions & 1 deletion greenland-sim.rb
Expand Up @@ -8,7 +8,8 @@
n2.times { sim_game.players << Player.new } # Edit n2 depending on how many players you need for this test!

# set player strategies
sim_game.players.each do |player|
sim_game.players.each_with_index do |player,i|
player.name = "Player-#{i}"
player.strategy = DoNothing.new(sim_game)
end

Expand Down
11 changes: 8 additions & 3 deletions greenland.rb
Expand Up @@ -274,6 +274,8 @@ def spring
player.tokens[:hunting_people] += 1
@hunters << player.name #test this!
puts "Okay #{player.name}, you've sent off one of your people to hunt seals!"
else
puts "Okay, no seal-hunting for you this turn!"
end
end

Expand Down Expand Up @@ -876,7 +878,7 @@ def name_players
@players.each_with_index do |player,i|
puts "Hey Player #{i+1}, what is your name?"
print ">> "
player.name = player.strategy.choose_name # $stdin.gets.chomp
player.name = $stdin.gets.chomp
end
end

Expand All @@ -886,7 +888,6 @@ def name_players
def play
puts "Welcome to Greenland!"
puts "The player with the most surviving people and the most silver at the end of the game wins. Good luck!"
self.name_players # Have players input their names
# Choose one player to be the dealer by rolling dice for highest.
@players.shuffle!
puts "#{@players.first.name} is the dealer, for now."
Expand All @@ -912,6 +913,10 @@ def play
@winners = @players.select { |player| player.total_points == @winner.total_points }
@winner_names = []
@winners.each { |player| @winner_names << player.name }
puts "#{@winner_names.join(" and ")} survived Greenland! Congratulations!"
if @winners != []
puts "#{@winner_names.join(" and ")} survived Greenland! Congratulations!"
else
puts "You all died. Greenland wins!"
end
end
end
47 changes: 16 additions & 31 deletions strategies.rb
Expand Up @@ -56,9 +56,6 @@ def build_barns_count

def build_boats_count
end

def choose_name
end
end

class StdInput < Strategy
Expand Down Expand Up @@ -135,88 +132,76 @@ def build_barns_count
def build_boats_count
$stdin.gets.chomp.to_i
end

def choose_name
$stdin.gets.chomp
end
end

class DoNothing < Strategy
def initialize(game)
super(game)
end

def sequence_point
$stdin.gets.chomp
end

def send_boats_count(boats)
# boats will be either :boats_hunting (for walrus-hunting) or :boats_in_vinland (for sending boats to vinland)
$stdin.gets.chomp.to_i
0
end

def send_boats_people_count(boats)
# boats will be either :boats_hunting (for walrus-hunting) or :boats_in_vinland (for sending boats to vinland)
$stdin.gets.chomp.to_i
0
end

def hunt_seals
$stdin.gets.chomp
n
end

def ivory_to_trade
$stdin.gets.chomp.to_i
0
end

def how_much_hay
$stdin.gets.chomp.to_i
0
end

def butchering_sheep_count
$stdin.gets.chomp.to_i
0
end

def butchering_cows_count
$stdin.gets.chomp.to_i
0
end

def cut_down_trees_count
$stdin.gets.chomp.to_i
0
end

def deconstruct_boats_count
$stdin.gets.chomp.to_i
0
end

def sheep_move_into_barns_count
$stdin.gets.chomp.to_i
0
end

def cows_move_into_barns_count
$stdin.gets.chomp.to_i
0
end

def feed_sheep_hay
$stdin.gets.chomp
n
end

def choose_dealer
$stdin.gets.chomp
@game.players.shuffle.first.name
end

def repair_barns_count
$stdin.gets.chomp.to_i
0
end

def build_barns_count
$stdin.gets.chomp.to_i
0
end

def build_boats_count
$stdin.gets.chomp.to_i
end

def choose_name
$stdin.gets.chomp
0
end
end

0 comments on commit 2a56fd0

Please sign in to comment.