import "basicbots"
- Constants
- Variables
- func FunctionCannon(env builtin.Environment, args []object.Object) object.Object
- func FunctionDamage(env builtin.Environment, args []object.Object) object.Object
- func FunctionDrive(env builtin.Environment, args []object.Object) object.Object
- func FunctionLocX(env builtin.Environment, args []object.Object) object.Object
- func FunctionLocY(env builtin.Environment, args []object.Object) object.Object
- func FunctionScan(env builtin.Environment, args []object.Object) object.Object
- func FunctionSpeed(env builtin.Environment, args []object.Object) object.Object
- func GetAngle(x1, y1, x2, y2 float64) float64
- func GetDistance(x1, y1, x2, y2 float64) float64
- func InitRobots() error
- func ResetRobots() error
- func RunRobots() error
- func Scanner(angle, width, b1x, b1y, b2x, b2y float64) float64
- func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string)
- func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string)
- func eventloop()
- func initDisplay() error
- func main()
- func movemissile()
- func moverobot()
- func plotbattlefield()
- type Missile
- type Robot
Constants for battlefield.
const (
MAXX = 1000.0 // MAXX : Maximum size of the battlefield in the X direction.
MAXY = 1000.0 // MAXY : Maximum size of the battlefield in the Y direction.
)
Constants for robot status.
const (
MAXROBOTS = 4 // MAXROBOTS : The maximum number of robots allowed.
ALIVE = 0 // ALIVE : Robot is functional.
DEAD = 1 // DEAD : Robot is dead.
ACCEL = 10.0 // ACCEL : Max Acceleration.
)
Constants for converting degrees to radians and back.
const (
DEG2RAD = 0.0174532925 // DEG2RAD : multiply 0-360 degrees to get radians.
RAD2DEG = 57.2957795130 // RAD2GEG : multiply radians to get degrees.
)
Constants for missile reload and movement.
const (
MAXMISSILES = 2 // MAXMISSILES : Maximum number if missiles a robot can have on the battlefield at one time.
MISSLERANGE = 700.0 // MISSLERANGE : Maxumum range of a missile.
RELOAD = 15 // RELOAD : Number of of movrment cycles for a missile reload.
MISSILESPEED = 500.0 // MISSILESPEED : Missiles move at full speed. No ramp up. 500 is 500% vs 100% for robots.
ROBOTRELOAD = 5 // ROBOTRELOAD : Number of cycles for the robot to reload. Used to slow down the firing of the second missile.
EXPLODECOUNT = 5 // EXPLODECOUNT : The number of momvement cycles for the explosion to show in the battlescreen.
)
Constants for missile status
const (
AVAILABLE = 1 // AVAILABLE : Missle is available for firing
FLYING = 2 // FLYING : Missile is in flight.
EXPLODE = 3 // EXPLODE : Missile is the process of exploding.
EXPLODING = 4 // EXPLODING : Blowing up
)
Constants for robots running into things.
const (
DAMAGEWALL = 2 // DAMAGEWALL : Amount of damage a robot will occure when it hits a wall.
DAMAGECOL = 4 // DAMAGECOL : Amount of damage a robot will occure when it hits another robot. Both robots take damamge.
)
Constants for missle dmaage and blast radius.
const (
MISFAR = 40 // MISFAR : Largest blast radius to cause damage.
MISNEAR = 20 // MISNEAR : Medium blast radius to cause damage.
MISCLOSE = 5 // MISCLOSE : Closest blast radius to cause damage.
DAMFAR = 3 // DAMFAR : Damage to robot at between MISNEAR and MISFAR
DAMNEAR = 5 // DAMNEAR : Damage to robot at between MISNEAR and MISCLOSE
DAMCLOSE = 10 // DAMCLOSE : Damage to robot when at or below MISCLOSE
)
Constants for cycles routines. Mainly movements.
const (
MOVECLICKS = 50 // CLICKS : Number of cycles between moverobot and movemissile.
)
var Missiles [MAXROBOTS][MAXMISSILES]Missile // Missile : Array of the missiles that can be used.
var Robots []Robot // Robots : Array of the robots
var battleSizeX int // battleSizeX : Size of the battlescreen on the console in the X direction.
var battleSizeY int // battleSizeY : Size of the battlescreen on the console in the Y direction.
var battledisplay bool // battledisplay : true show graphics
var boxStyle tcell.Style // boxStyle : Leagacy purple
var current int // current : The current active robot
var cycledelay int64 // cycledelay : Delay in nanoseconds. Used in the battlescreen mode to slow down the play.
var cycles int // cycles : The number of cpu cycles
variables
var debug bool // debug : Debug flag
var defStyle tcell.Style // defStyle : white on blank for text. Used in tcell.
var evaluator []*eval.Interpreter // evaluator : Slice of Interpreters.
var event = make(chan int) // event : Channel for getting out of tcell with escape key.
var lox float64 // lox : scaling factor for battlefield to console area.
var loy float64 // loy : scalling factor for battlefield to console area.
var matchcount int // matchcount : Number of matches to play with current robots. Can not be used with 'battledisplay'.
var maxCycles int // maxCycles : Maximum numer of cycles per match. Can change with cli flag.
var numberOfRobots int // numberOfRobots : The number of robots in this simulation
var scr tcell.Screen // scr : tcell screen interface. Using global to keep from haveing go routines.
var token []*tokenizer.Tokenizer // token : slice of tokienizers
var trace bool // trace : Trace flag
func FunctionCannon(env builtin.Environment, args []object.Object) object.Object
FunctionCannon : Basic statement. CANNON direction, range. Fire the cannon at angle and distance. Do nothing if no missiles available.
func FunctionDamage(env builtin.Environment, args []object.Object) object.Object
FunctionDamage : Basic statement. DAMAGE returns the current damage of the robot
func FunctionDrive(env builtin.Environment, args []object.Object) object.Object
FunctionDrive : Basic statement. DRIVE direction,speed sets speed and direction
func FunctionLocX(env builtin.Environment, args []object.Object) object.Object
FunctionLocX : Basic statement. LOCX returns the current Y location.
func FunctionLocY(env builtin.Environment, args []object.Object) object.Object
FunctionLocY : Basic statement. LOCY returns the current Y location
func FunctionScan(env builtin.Environment, args []object.Object) object.Object
FunctionScan : Basic statement. SCAN direction,width. Scan the battlefield in direction with a width of +/- width
func FunctionSpeed(env builtin.Environment, args []object.Object) object.Object
FunctionSpeed : Basic statement. SPEED returns the current speed of the robot
func GetAngle(x1, y1, x2, y2 float64) float64
GetAngle : Return the angle in degrees from x1,y1 to x2,y2
func GetDistance(x1, y1, x2, y2 float64) float64
GetDistance : Return the distance between x1,y1 to x2,y2
func InitRobots() error
func ResetRobots() error
func RunRobots() error
func Scanner(angle, width, b1x, b1y, b2x, b2y float64) float64
Scanner : Scan angle with within x,y of both robots. Returns distance if robot found or 0 if none found.
func drawBox(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string)
drawBox : Draws a box bording x1,y1 & x2,y2. Uses style for forground and background colors. text puts a string in the upper left corner od the box.
func drawText(s tcell.Screen, x1, y1, x2, y2 int, style tcell.Style, text string)
drawText : Puts text onthe screen at x1,y1 to x2,y2 using style for forground and background colors.
func eventloop()
evenloop : go routine for processing tcell events. Channel even passes back to main program to terminate.
func initDisplay() error
initDisplay : Initialize tcell
func main()
func movemissile()
movemissile : move all flying missiles per motion click. Check for blast damage, htting wall, etc.
func moverobot()
moverobot : Move robots every motion cycle. Take damage, detect dead robots, detect for collision.
func plotbattlefield()
plotbattlefield : Erase and Draw the robots, missiles and blasts on the battlefield as well as the side status.
Missle : type struct for holding missle variables.
type Missile struct {
X float64 // X : Current X location of the missile.
Y float64 // Y : Current Y location of the missile.
XOrigin float64 // XOrigin : Origin point from the last X location. Used in movement for directions.
YOrigin float64 // YOrigin : Origin point from the lasy Y location. Used in movement for ditections.
XO float64 // XO : Origin point from the last X location. Used in movement for directions.
YO float64 // YO : Origin point from the lasy Y location. Used in movement for ditections.
XPlotOld int // XPlotOld : Last battlefield X position. Used for erasing the old marker.
YPlotOld int // YPlotOld : Last battlefield Y position. Used for erasing the old marker.
Heading float64 // Heading : Heading of the missile.
Distance float64 // Distance : The set distance at which the missile explodes.
Status int // Status : The status of the missile. Available,flying,exploding.
Reload int // Reload : Movement clicks until reloaded.
ExplodeCount int // ExplodeCount : Time in motion cycles to have explosion showing.
}
Robot : type struct for holding robot variables
type Robot struct {
Name string // Name : The name of the robot
X float64 // X : Current X of the robot.
Y float64 // Y : Current Y of the robot.
XOrigin float64 // XOrigin : orgin x location. Used in movement.
YOrigin float64 // YOrigin : orgin y location. Used in movement.
XPlotOld int // XPlotOld : Last X plot on the battlefield. Used to remove the past marker.
YPlotOld int // YPlotOld : Last Y plot on the battlefield. Used to remove the past marker.
Damage int // Damage : Current state of the damage of the robot
Speed float64 // Speed : Current speed of the robot.
SpeedWanted float64 // SpeedWanted : The desired speed of the robot.
SpeedHold float64 // SpeedHold : Holds the previous speed while in a turn.
Heading float64 // Heading : Current heading of the robot
HeadingWanted float64 // HeadingWanted : The disired heading of the robot.
Distance float64 // Distance : The Distance the robot has traveled from the origin point.
Scan float64 // Scan : Scan heading. 0-360
Width float64 // Width : Scan width 2-10
Cannon float64 // Cannon : Vannon heading
Reload int // Reload : Countdown until cannon reload is complete
Status int // Status : Status of the robot. Dead or Alive.
Winner int // Winner : Number of wins
Lose int // Lose : Number off times lost
Tie int // Tie : Number of times tied
Program []byte // Program : Byte slice holding the program's text file.
}
Generated by gomarkdoc