Class: Script

Inherits:
Object
  • Object
show all
Defined in:
lib/ttr/sample/script.rb

Overview

Copyright © 2011 Jesse Sielaff

Class Method Summary collapse

Class Method Details

.sample(game, player) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ttr/sample/script.rb', line 7

def Script.sample (game, player)
  until player.turn_completed?
    case rand
      when 0...0.01
        player.draw_tickets
        a, b, c = player.candidate_tickets
        player.keep_ticket(a)
        player.keep_ticket(b) if rand < 0.1
        player.keep_ticket(c) if rand < 0.1
        player.discard_tickets
      
      when 0.01...0.1
        game.unclaimed_routes.shuffle.any? do |route|
          %w:black blue green orange pink red white yellow:.shuffle.any? do |color|
            player.claim_n_wild(route, color.to_sym, rand(7))
          end
        end
      
      when 0.1...0.2
        player.select_card(game.available_colors.sample)
      
      else
        player.draw_random
    end
  end
end