36 lines
878 B
Crystal
36 lines
878 B
Crystal
module GameOfGame
|
|
abstract class Ai
|
|
end
|
|
end
|
|
|
|
require "./game_history"
|
|
|
|
module GameOfGame
|
|
|
|
# Interface
|
|
abstract class Ai
|
|
# returns a proc that identify self in a Hash(Ai, Float64)
|
|
# useful for `last_round.bets.reject(me)` for instance
|
|
def me
|
|
Proc(Ai, Float64, Bool).new { |player, _| player == self }
|
|
end
|
|
|
|
getter name : String
|
|
@@id_incr = 0
|
|
|
|
def initialize(name = nil)
|
|
@name = name || "Player_#{self.class.to_s.split("::").last}_#{Ai.make_id}"
|
|
end
|
|
|
|
def self.make_id : String
|
|
(@@id_incr += 1).to_s.rjust(3, '0')
|
|
end
|
|
|
|
# This method allows the player to place a bet on the current round given a
|
|
# known historic of previous plays. Memory is perfect here so we can
|
|
# examine total score, last score, last plays, all plays for every players.
|
|
abstract def bet(rounds : GameHistory) : Float64
|
|
end
|
|
|
|
end
|