TurtleField Quick Reference

20-NOV-2021, Y. Hayakawa (CDS, Tohoku Univ.)

Go functions associated with Turtle structconnect to server Connect(hostname)use TCP port 2222

Turtle Graphics

clear screen Clr()
origin is the center of square
home position Home()
pen up Pu()
pen down Pd()
step forward Fd(step)
step back Bk(step)
unit of length: pixel
jump Jump(x, y)
relative jump Rjump(dx, dy)turn left Lt(angle)
unit of angle: degree
turn right Rt(angle)
print string Say(string)line mode Line()brush mode Brush()
max # of vertices in filling mode: 6filling mode Fill()
type: 1..53
display card Card(type,x,y)
clear card ClrCard
returns [x, y]
query curr. position Q_Pos()
returns angle
query heading direction Q_Dir
0.0 < red green, blue < 1.0
pen color Col(red, green, blue)
background color Bgc(red, green, blue)

Battles & robot simulations

Regulations/limitations in battle (robot) mode
step size of Fd() & Bk(): up to 2 pixels
turning angle: up to 3 degrees
field is surrounded by rigid walls
only single bullet can exist at a moment in the field for each turtle

Callback registration
SetHitByBulletCallback(func(Turtle,int))
SetRunIntoTurtleCallback(func(Turtle,int))
SetRunIntoDonutCallback(func(Turtle,int))
SetRunIntoStoneCallback(func(Turtle,int))
SetRunIntoWallCallback(func(Turtle,int))
SetFoundCoinCallback(func(Turtle,int))
SetDetectedByFinder(func(Turtle,int))
SetDetectedByRadarCallback(func(Turtle,int))
SetGotMessageCallback(func(Turtle,int))
time code is passed in 2nd arg. of the callback

Scoring
initial score of each: 100
point to loose for each shoot: -1
hitting other turtle: +10
hit by bullet:-30
hitting donut within short distance: +10
when score < 0, disconnected

methods
FINDER front sensor
switch to battle mode Bmode()default: 20
use Rf() to changeswitch to graphics mode Gmode()shoot a bullet Fire
set nickname Nm(name)set my team number Tm(team_id) 0<=team_id<=4query number of objects Q_Nt()# of turtles and donuts
result code = 0: no objects within effective range
query to finder Q_Finder() returns code1: turtle 2: donut 3: stone 4: wall found
set range of finder Rf(range)
query to angular radar Q_Radar() returns angle
RADAR angular sensor
query to sonar Q_Sonar() returns [left, front, right]
anticlockwise>0
query my current score Q_Score() returns current score
query team id of turtle met just before Q_Tm() returns the id (use this after Q_Ffinder()angle to the nearest
or Q_Radar() calls)
put a robot turtle in the field Robot()object (turtle or donut)
scatter a donut in the field Donut() max 10 donuts for eachscatter a coin in the field Coin()borrow 10 coins from the TF owner BorrowCoin() max 300 coins in the fieldmeasurement error: 20 deg
drop a coin at current position DropCoin()
SONAR obstacle detector
pick one coin near current position PickCoin()array index = 0
check number of coin at near distance Q_Coin()returns the numberfor each direction
1
broadcast message to team members Bcas(message)
false: no obstacle, true: obstacle foundwithin 20 pixels
returns the message
query team message Q_Bcas()
2

C, Java, Ruby, and Python APIs are available at TurtleField web site:

https://wagtail.cds.tohoku.ac.jp/coda/tfield/index.html

Usage of Turtle Field serverright click on screen to pop up menu

size of turtle: 20 pixels in diameterpress capital M: enter maze mode
3: toggle b/w 2D and 3D modes

clear field clear drawing
http port for Turtle Field Live: 2280
erase zombie erase turtles that lost TCP connections
toggle graphics/battle mode in battle mode, background texture changes
toggle private/public mode in public mode connections from any addr. are accepted. window title bar changes
capture screen save screen shot in home (UNIX) or desktop (Windows)
kill all turtles
exit