Queue tests
This commit is contained in:
17
src/map.cr
17
src/map.cr
@ -14,22 +14,15 @@ struct Point
|
||||
end
|
||||
|
||||
abstract class Tile
|
||||
property cap : Int32 = 0
|
||||
|
||||
def initialize(@point : Point)
|
||||
@cap = 0
|
||||
@cur = 0
|
||||
end
|
||||
|
||||
def point
|
||||
@point
|
||||
end
|
||||
|
||||
def cap
|
||||
@cap
|
||||
end
|
||||
|
||||
def cur
|
||||
@cur
|
||||
end
|
||||
getter point
|
||||
getter cap
|
||||
getter cur
|
||||
|
||||
def withdraw(value)
|
||||
if value >= @cur
|
||||
|
14
src/queue.cr
14
src/queue.cr
@ -1,25 +1,25 @@
|
||||
class App::Queue(T)
|
||||
struct Item(T)
|
||||
def initialize(@ts : Int32, @value : T)
|
||||
class App::Queue
|
||||
struct Item
|
||||
def initialize(@ts : Int32, @command : Command)
|
||||
end
|
||||
|
||||
getter ts
|
||||
getter value
|
||||
getter command
|
||||
end
|
||||
|
||||
def initialize
|
||||
@data = [] of Item(T)
|
||||
@data = [] of Item
|
||||
end
|
||||
|
||||
# Plan finishing of *command* at time *ts*
|
||||
def push(ts : Int32, value : T)
|
||||
def push(ts : Int32, value : Command)
|
||||
@data.push(Item.new(ts, value))
|
||||
@data.sort! do |a, b|
|
||||
b.ts <=> a.ts
|
||||
end
|
||||
end
|
||||
|
||||
def pop(ts : Int32) : Item(T) | Nil
|
||||
def pop(ts : Int32) : Item | Nil
|
||||
if @data.size == 0
|
||||
return nil
|
||||
end
|
||||
|
@ -21,7 +21,7 @@ class World
|
||||
@ts = 0
|
||||
@resources = Resources.new
|
||||
@map = Map.new
|
||||
@queue = App::CommandQueue.new
|
||||
@queue = App::Queue.new
|
||||
end
|
||||
|
||||
private def ts
|
||||
@ -49,8 +49,8 @@ class World
|
||||
if item.nil?
|
||||
break
|
||||
end
|
||||
command_ts, command = item[:ts], item[:cmd]
|
||||
@ts = command_ts
|
||||
command = item.command
|
||||
@ts = item.ts
|
||||
command.finish(self)
|
||||
printf "world : %d : finish `%s`\n", @ts, typeof(command)
|
||||
end
|
||||
|
Reference in New Issue
Block a user