Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
test() ->
12 = area({rectangle, 3, 4}),
144 = area({square, 12}),
tests_worked.
require "prawn"
class CustomReport
def initialize(document)
@document = document
end
def header(message)
draw { text(message, :size => 32) }
end
def ellipse(point, r1, r2 = r1)
x, y = point
l1 = r1 * KAPPA
l2 = r2 * KAPPA
create_path do |path|
path.move(x + r1, y)
.curve(x, y + r2, x + r1, y + l2, x + l1, y + r2)
.curve(x - r1, y, x - l1, y + r2, x - r1, y + l2)
.curve(x, y - r2, x - r1, y - l2, x - l1, y - r2)
@practicingruby
practicingruby / x.rb
Last active December 30, 2015 01:08
Tests for a game object in "Hunt The Wumpus". Please help improve its clarity.
require_relative "../helper"
describe "A room" do
let(:room) { Wumpus::Room.new(12) }
it "has a number" do
room.number.must_equal(12)
end
it "may contain hazards" do
bats = Hazard.new(:bats)
bats.sensed("You hear a rustling sound.")
bats.encountered do |narrator|
narrator.say("Giant bats whisk you away to a new cavern!")
new_room = random_room
move(:bats, from: current_room, to: new_room)

"What in the world is a Wumpus?", Ruth asked.

"It's a terrible cave-dwelling beast", said Grandpa Joe, "and by golly, we're going to hunt it!"

Ruth looked at the old man and sighed deeply. It would seem that she had got her hopes up for nothing, and that today would be the usual mix of boring and crazy she had come to expect from her grandfather.

wumpus_room = rand(2..10)
current_room = 1
loop do
puts
if current_room == 0
puts "You escaped the cave unharmed,"
puts "but the wumpus still lurks in the shadows. GAME OVER!"
exit

(Extracted from Practicing Ruby Issue 7.1)

Exploratory programming as a first-class paradigm?

Even though we've managed to pack a lot of interesting behavior into a small amount of code, the examples I've shown here barely scratch the surface of StarLogo and capabilities. While my Terrarium engine is nothing more than a poor man's implementation of a few of StarLogo's features, the full StarLogo language is elegantly designed and carefully thought out.

But the goal of this article was not to introduce you to a shiny piece of technological infrastucture, it was meant to get you thinking about a different kind of workflow than what we tend to use day to day. Even through the smudged window I've had you look through, it should be clear to see that the style of programming used in StarLogo has several powerful benefits:

  • Thoughts can be expressed directly
  • Feedback is given continuously
# NOTE: Maybe have a factory to split objects between "Immediate" mode and
# everything else
class Cell
def initialize(processor, mode)
@processor = processor
@mode = mode
compute_address
end
module Vintage
class Processor
OPCODES = { 0xa9 => :LDA, 0x8D => :STA }
def initialize
@acc = 0
@memory = {}
end
attr_reader :acc, :memory