Skip to content

Instantly share code, notes, and snippets.

@cnosuke
Last active December 19, 2015 10:29
Show Gist options
  • Save cnosuke/5940434 to your computer and use it in GitHub Desktop.
Save cnosuke/5940434 to your computer and use it in GitHub Desktop.
ECARD from KAIJI
require 'pry'
module ECard
class Game
attr_reader :players
def initialize
@players = [ Player.new(:emperor), Player.new(:slave) ]
end
def fight
compare(@players.first.select, @players.last.select)
end
def compare(a,b)
if a.role_point * b.role_point == -1
return -1
else
a.role_point <=> b.role_point
end
end
end
class Player
attr_reader :cards
def initialize(role)
@cards = [ Card.new(role)]
4.times{ @cards << Card.new(:citizen) }
end
def select
@cards.shuffle!.pop
end
end
class Card
attr_reader :role
def initialize(role)
@role = role
end
def role_point
{
:emperor => 1,
:citizen => 0,
:slave => -1
}.fetch(@role)
end
end
end
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment