0% found this document useful (0 votes)
119 views3 pages

Tile World

This document describes an artificial intelligence simulation called Tileworld. In Tileworld, robots push tiles around a gridded world in an attempt to move the tiles onto holes before they disappear. Tiles and holes are born randomly on the grid over time. The robots use a greedy strategy, trying to push the closest tile to the closest hole. This strategy works well with one robot but causes issues with multiple robots getting in each other's way. The document provides code for setting up the Tileworld simulation and defining rules for how robots, tiles, and holes behave and interact.

Uploaded by

joseangelini
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views3 pages

Tile World

This document describes an artificial intelligence simulation called Tileworld. In Tileworld, robots push tiles around a gridded world in an attempt to move the tiles onto holes before they disappear. Tiles and holes are born randomly on the grid over time. The robots use a greedy strategy, trying to push the closest tile to the closest hole. This strategy works well with one robot but causes issues with multiple robots getting in each other's way. The document provides code for setting up the Tileworld simulation and defining rules for how robots, tiles, and holes behave and interact.

Uploaded by

joseangelini
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

; Tileword

; by
; Jose M Vidal
;
; Tileworld was (first?) described in:
;
;Martha Pollack and Marc Ringuette. "Introducing the Tileworld: experimentally
evaluating agent architectures."
;Thomas Dietterich and William Swartout ed. In Proceedings of the Eighth National
Conference on Artificial
; Intelligence, p. 183--189, AAAI Press. 1990.

breed [ robots ]
breed [ tiles ]
breed [ holes ]

tiles-own [time-to-live]

holes-own [time-to-live]

;desitnation- the next place I am heading towards


robots-own [destination-x destination-y]

globals [holes-born holes-filled score]

to setup
ca
set-default-shape tiles "box"
set-default-shape holes "circle"
create-robots num-robots [
setxy get-random-xcor get-random-ycor]
end

to-report get-random-xcor
report (random world-width) + min-pxcor
end

to-report get-random-ycor
report (random world-height) + min-pycor
end

to update
if (random-float 1.0 < tile-birth-prob) [
create-tiles 1 [
set heading 0
set time-to-live tile-lifetime
setxy get-random-xcor get-random-ycor
set color yellow]]
if (random-float 1.0 < hole-birth-prob) [
set holes-born holes-born + 1
create-holes 1 [
set heading 0
set time-to-live hole-lifetime
setxy get-random-xcor get-random-ycor
set color blue]]

tileworld - page 1
ask tiles [age]
ask holes [age]
no-display
ask robots [move]
display
; plot holes-filled
if (holes-born > 0)[
set score holes-filled * 100 / holes-born
plot score]
end

;reports one of 0,90,180,270; whichever is closest to h


to-report rectify-heading [h]
if (h < 0)[
set h (360 + h)]
if (h <= 45)[
report 0]
if (h <= 135)[
report 90]
if (h <= 225)[
report 180]
if (h <= 315)[
report 270]
report 0
end

;tiles and holes


to age
if time-to-live <= 0 [die]
set time-to-live time-to-live - 1
end

;tiles

;sets destination-of robot to be the location where robot should be


; in order to push me towards hole.
;HINT: This is a bad way to move tiles. Specifically, if the hole is on a diagonal
; from the tile, the robot tends to move back-and-forth a lot.
to set-robot-destination [robot hole]
carefully ;in case robot is at hole. thanks Paolo Petta
[set heading rectify-heading (towards hole)][]
set heading heading + 180
let the-patch patch-at dx dy
ask robot [
set destination-x [pxcor] of the-patch
set destination-y [pycor] of the-patch
]
;set [destination-x] of robot [pxcor] of patch-at dx dy
;set [destination-y] of robot [pycor] of patch-at dx dy
end

;robots

; This is the obvious greedy strategy.


; It tries to push the closest tile to the closest hole. This is a great
; strategy when there is only one robot, but when there are many you end up

tileworld - page 2
; with all of them getting in each others' way.
to move
let closest-tile 0
let closest-hole 0

set closest-tile min-one-of tiles [distance myself]


set closest-hole min-one-of holes [distance myself]
if (closest-tile != nobody)[
ifelse (closest-hole != nobody)[
ask closest-tile [set-robot-destination myself closest-hole]
if (xcor = destination-x and ycor = destination-y)[
;Im already at the desired location, so push the tile
set heading rectify-heading towards closest-tile
move-one heading
stop]]
[;there are no holes in the field, this typically only happens at the beginning
of the run.
set destination-x [xcor] of closest-tile
set destination-y [ycor] of closest-tile]

;I am not next to the tile, so set my heading towards the best position next to
it.
set heading rectify-heading towardsxy destination-x destination-y

;If my move will cause a tile to move then change direction by +- 90.
;This will, hopefully, allow me to move around the target to push it back.
if (any? tiles-at dx dy)[
ifelse (random-float 1.0 < .5)[
set heading heading + 90]
[
set heading heading - 90]]
move-one heading]
end

;moves the agent one step with in the absolute heading h.


;It makes sure that any tile or robot that was in the destination location also
moves, and so on recursively.
;If a tile moves into a hole, both die.
to move-one [h]
let pushed-agents 0
let oldh 0

set oldh heading


set heading h
set pushed-agents (turtles-at dx dy) with [(breed = robots) or (breed = tiles)]
if (any? pushed-agents) [
ask pushed-agents [move-one h]]
if (breed = tiles and (any? holes-at dx dy))[
set holes-filled holes-filled + 1
ask holes-at dx dy [die]
die]
fd 1
set heading oldh
end

tileworld - page 3

You might also like