diff --git a/bofa/Makefile b/bofa/Makefile new file mode 100644 index 0000000..267b454 --- /dev/null +++ b/bofa/Makefile @@ -0,0 +1,3 @@ +bot.zip: src/main/scala/bot/*.scala + cd src/main/scala/bot && sed -i 's/Boolean = true/Boolean = false/' DebugUtil.scala + cd src/main/scala && zip -r bot bot && mv bot.zip $(CURDIR) diff --git a/bofa/src/main/scala/bot/Cortex.scala b/bofa/src/main/scala/bot/Cortex.scala index 01ed866..16a6448 100644 --- a/bofa/src/main/scala/bot/Cortex.scala +++ b/bofa/src/main/scala/bot/Cortex.scala @@ -15,25 +15,42 @@ final case object Right extends { val label = "right"; val deltaX = 1; val delta final case object Up extends { val label = "up"; val deltaX = 0; val deltaY = -1 } with Direction final case object Down extends { val label = "down"; val deltaX = 0; val deltaY = 1 } with Direction +object Scribble { + var lastFieldWeight = 0 + var lastBofaField: Field = Field.empty +} + class Cortex { def move(state: State, time: Int): Direction = { val directions: Seq[Direction] = possibleDirections(state.bofaField, state) - val weightBoard = weightCodes(1000, decr, state) + + val weightBoard = weightCodes(1000, decr, state) + preventFallBack(weightBoard, state) + val dir = getMaxDir(state.bofaField, directions, weightBoard, state) + + Scribble.lastBofaField = state.bofaField + weightBoard(state.bofaField.x)(state.bofaField.y) = -999 printBoard(weightBoard) - + dir } def decr(dist: Int, start: Int) = { - (start/math.pow(2, (dist+1))).intValue() + val d = (start/math.pow(2.5, (dist+1))).intValue() + if (d < 5) 5 else d } def getMaxField(weightBoard: Array[Array[Int]], state: State): Field = { var maxField = (0,0) for (x <- 0 until S.width; y <- 0 until S.height) { + // generally, the highest is best if (weightBoard(x)(y) > weightBoard(maxField _1)(maxField _2)) maxField = (x,y) + // if equal prefer to go down, right b/c up/left is evil first but + if (weightBoard(x)(y) == weightBoard(maxField _1)(maxField _2)){ + if (x > (maxField _1) || y > (maxField _2)) maxField = (x, y) + } } state.board(maxField _1)(maxField _2) @@ -54,11 +71,14 @@ class Cortex { var (maxX, maxY) = (mod (field.x+maxDir.deltaX) (S.width), mod (field.y+maxDir.deltaY) (S.width)) if (weightBoard(x)(y) > weightBoard(maxX)(maxY)) maxDir = d + } maxDir } + def manhattan(x: Int, y: Int)(a: Int, b: Int): Int = math.abs(x-a) + math.abs(y-b) + def possibleDirections(field: Field, state: State): Seq[Direction] = { val pd = new mutable.ListBuffer[Direction] val board = state.board @@ -79,6 +99,22 @@ class Cortex { pd } + def preventFallBack(weightBoard: Array[Array[Int]], state: State): Unit = { + val lastBofaField = Scribble.lastBofaField + + if (lastBofaField != Field.empty){ + // if something changed allow fallback + log(s"lastFieldWeight=${Scribble.lastFieldWeight}") + if (Scribble.lastFieldWeight == weightBoard(lastBofaField.x)(lastBofaField.y)){ + Scribble.lastFieldWeight = weightBoard(state.bofaField.x)(state.bofaField.y) + val x: Int = weightBoard(lastBofaField.x)(lastBofaField.y) + weightBoard(lastBofaField.x)(lastBofaField.y) = (x - (0.1 * x)).intValue() + } else{ + Scribble.lastFieldWeight = weightBoard(state.bofaField.x)(state.bofaField.y) + } + } + } + def weightCodes(start: Int, drop: (Int, Int) => Int, state: State): Array[Array[Int]] = { val board = state.board val codes = state.codes diff --git a/bofa/src/main/scala/bot/DebugUtil.scala b/bofa/src/main/scala/bot/DebugUtil.scala index 9e87a9b..0af4f3b 100644 --- a/bofa/src/main/scala/bot/DebugUtil.scala +++ b/bofa/src/main/scala/bot/DebugUtil.scala @@ -2,9 +2,9 @@ package bot object DebugUtil { var state: Option[State] = None // we need this to get access to the current game round - val Dbg: Boolean = true - val Log: Boolean = true - val Time: Boolean = true + val Dbg: Boolean = false + val Log: Boolean = false + val Time: Boolean = false def dbg(msg: String) = if(Dbg) Console.err.println(s"$round $msg") def log(msg: String) = if(Log) Console.err.println(s"$round $msg")