Skip to content

Commit

Permalink
Update seed data for games.
Browse files Browse the repository at this point in the history
  • Loading branch information
saterus committed Apr 19, 2012
1 parent ed09b10 commit 66d579d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion db/seeds.rb
Expand Up @@ -17,13 +17,27 @@
Player.create(name: "Peggy") Player.create(name: "Peggy")
] ]


def rand_game(match, player_one, player_two)
w = 11
l = 11 - (rand(5) + 1)
if rand > 0.75
match.games.build(winner: player_one, winner_score: w,
loser: player_two, loser_score: l)
else
match.games.build(winner: player_two, winner_score: w,
loser: player_one, loser_score: l)
end
end

def rand_match(time) def rand_match(time)
player_one = @players[rand(@players.size)] player_one = @players[rand(@players.size)]
player_two = @players[rand(@players.size)] player_two = @players[rand(@players.size)]
while player_one == player_two while player_one == player_two
player_two = @players[rand(@players.size)] player_two = @players[rand(@players.size)]
end end
Match.create(winner: player_one, loser: player_two, occured_at: time) match = Match.new(winner_score: 0, loser_score: 0, occured_at: time)
3.times { |i| rand_game(match, player_one, player_two) }
match.save!
end end


# Make up two weeks worth of matches to play around with. # Make up two weeks worth of matches to play around with.
Expand Down

0 comments on commit 66d579d

Please sign in to comment.