fixed gate overflow bug

This commit is contained in:
Armin Friedl 2017-11-05 22:50:13 +01:00
parent 0fdb836e82
commit 2b0ef1ac82
3 changed files with 6 additions and 9 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
bot.zip
# Created by https://www.gitignore.io/api/sbt,linux,scala,eclipse

View file

@ -43,16 +43,17 @@ class Cortex {
0
}
def mod(a: Int)(b: Int): Int = (a % b) + (if (a < 0) b else 0)
def getMaxDir(field: Field, directions: Seq[Direction], weightBoard: Array[Array[Int]], state: State): Direction = {
var maxDir: Direction = randomDirection(directions)
val board = state.board
for (d <- directions){
var (x,y) = (field.x+d.deltaX, field.y+d.deltaY)
if ( d.equals(Left) && board(field.x)(field.y).citizens.contains(Gate("l")) ) x = S.width-1
else if ( d.equals(Right) && board(field.x)(field.y).citizens.contains(Gate("r")) ) x = 0
var (x,y) = (mod (field.x+d.deltaX) (S.width), mod (field.y+d.deltaY) (S.width))
var (maxX, maxY) = (mod (field.x+maxDir.deltaX) (S.width), mod (field.y+maxDir.deltaY) (S.width))
if (weightBoard(x)(y) > weightBoard(field.x+maxDir.deltaX)(field.y+maxDir.deltaY)) maxDir = d
if (weightBoard(x)(y) > weightBoard(maxX)(maxY)) maxDir = d
}
maxDir

View file

@ -1,5 +0,0 @@
package bot
trait Extracted