-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
nddrylliog
committed
Jun 19, 2010
1 parent
24eb2f7
commit c306434
Showing
7 changed files
with
228 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import AI, Grid, Vector2, Canvas, math, math/Random | ||
|
||
Ndd2AI: class extends AI { | ||
|
||
// constants | ||
ZOOM := static 11.0 | ||
BUMP_THRESHOLD := static 5 | ||
|
||
left := true | ||
bumpCount := 0 | ||
|
||
printCount := 0 | ||
|
||
lastPos : Vector2 | ||
|
||
grid := Grid new(300, 200) | ||
|
||
stepImpl: func (info: GameInfo@) { | ||
|
||
answer prevWeapon = false | ||
answer nextWeapon = false | ||
answer wantedWeapon = 0 | ||
|
||
// get our grid coordinates | ||
gridx := (info pos x / ZOOM) as Int | ||
gridy := (info pos y / ZOOM) as Int | ||
|
||
if (left) { | ||
left() | ||
mouse(-50, 0) | ||
} else { | ||
right() | ||
mouse(50, 0) | ||
} | ||
|
||
// if we reached this position, it means it's empty, right? | ||
for(offx: Int in (-2)..3) { | ||
for(offy: Int in (-2)..3) { | ||
grid empty(gridx + offx, gridy + offy) | ||
} | ||
} | ||
|
||
// | ||
if((lastPos x - info pos x) abs() < 4.0) { | ||
bumpCount += 1 | ||
} else { | ||
bumpCount = 0 | ||
} | ||
|
||
// jump if there's a deadend in front of us | ||
if(grid search(gridx + (left ? -8 : 8), gridy + 2, 5, 4, Blocks DEADEND)) { | ||
jump() | ||
} | ||
|
||
if(bumpCount > BUMP_THRESHOLD) { | ||
bumpCount = 0 | ||
grid deadend(gridx + (left ? -6 : 6), gridy + 4) | ||
left = !left | ||
} | ||
|
||
// detect ground | ||
hasGround := grid search(gridx, gridy + 4, 2, 2, Blocks WALL) | ||
if(hasGround) { | ||
grid ground(gridx + (left ? -3 : 3), gridy + 5) | ||
} | ||
|
||
// detect ceilings | ||
hasCeil := grid search(gridx, gridy - 4, 2, 2, Blocks WALL) | ||
if(hasCeil) { | ||
grid ceil(gridx + (left ? -3 : 3), gridy - 6) | ||
} | ||
|
||
printCount -= 1 | ||
if(printCount <= 0) { | ||
printCount = 3 | ||
grid print(gridx, gridy) | ||
} | ||
|
||
lastPos x = info pos x | ||
lastPos y = info pos y | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import EagleAI, NddAI, AI | ||
import EagleAI, NddAI, Ndd2AI, AI | ||
|
||
getAI: unmangled func -> AI { | ||
return NddAI new() | ||
return Ndd2AI new() | ||
//return NddAI new() | ||
//return EagleAI new() | ||
} |
Oops, something went wrong.