-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworm-brain.rb
85 lines (73 loc) · 2.22 KB
/
worm-brain.rb
1
2
3
4
5
6
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'gosu'
require 'texplay'
require 'matrix'
class FoodEnvironment
def initialize(window)
@window = window
# At least to start, lets model our food environment
# by breaking the environment up into a grid. We'll
# store in a matrix the quantity of food located in
# each section of the grid
# At least to test the visualization with something neat
# Let's start by initializing with random values of
# between zero and three units of food in each section
@food_values = Matrix.rows(
(0...48).to_a.map { |row_number|
(0...64).to_a.map { |column_number|
rand(0..3)
}
})
end
def sniff(x, y, orientation)
# Put logic for simulated worm nose here
# worm will invoke this method passing its position
# and the direction (in radians) in which the nostril
# is pointed. Will return a value representing the food
# density in that direction for the specified position
# that the worm can map to the input neurons for that nostril
end
def consume_food(x, y)
# We'll have our worm consume all the food in the section
# of the grid in which it is located.
# Removes the food from the section of the environment
# in which x, y is located, and
# returns the quantity of food consumed
# So worm can simulate digestion
end
def print
end
def draw
# draws the food densities of the environment by drawing a
# red box over the section when there is food there.
# The brightness corresponds to the quantity of food
# in that section.
@food_values.each_with_index do |amount, row, col|
if amount != 0
color = Gosu::Color.argb(0x44440000 * amount)
@window.draw_quad(
col * 10, row * 10, color,
col * 10 + 10, row * 10, color,
col * 10 + 10, row * 10 + 10, color,
col * 10, row * 10 + 10, color)
end
end
end
end
class MyWindow < Gosu::Window
def initialize
super(640, 480, false)
self.caption = 'Hello Worm Brain World!'
@environment = FoodEnvironment.new(self)
end
def update
# run worm brain logic here for however many internal ticks
# and update the worm's state and environment
# and trigger actions of the worm based on the brain's
# output
end
def draw
@environment.draw
end
end
window = MyWindow.new
window.show