Skip to content

Commit

Permalink
Case Reade 및 Kingdom Rush 병함
Browse files Browse the repository at this point in the history
  • Loading branch information
nephilim committed May 6, 2012
1 parent 02261af commit e92c375
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/scala/misc/codejam/common/Combinator.scala
Expand Up @@ -18,3 +18,6 @@ object Combinator {
}}
}

object Permutator {

}
34 changes: 34 additions & 0 deletions src/main/scala/misc/codejam/srb/CaveInfoReader.scala
@@ -0,0 +1,34 @@
//package misc.codejam.sra
//
//import scala.collection.mutable.ListBuffer
//
//import misc.codejam.common.CodejamCaseReader
//import misc.codejam.common.Headline
//import misc.codejam.sra.LevelInfo
//import misc.codejam.srb.CellInfo
//
//class CaveInfoReader(resourcePath: String)
// extends CodejamCaseReader[CellInfo](resourcePath)
// with Headline {
//
// // chunk 처리용 type 선언
// type ChunkType = List[List[CellInfo]]
//
// override val headLine = lines.next
//
// override def readNext(): List[LevelInfo] = {
//// val totalLevel = lines.next.toInt
//// require(totalLevel > 0)
////
//// val levelInfos:ListBuffer[LevelInfo] = ListBuffer();
////
//// for (idx <- 1 to totalLevel) {
//// val Array(oneStar, twoStar) = lines.next.split(" ")
//// // val levelInfo = new CellInfo(idx, oneStar.toInt, twoStar.toInt, StarLevel.NotFished)
//// // levelInfos+= levelInfo
//// }
//// levelInfos.toList
// Nil
// }
//
//}
13 changes: 13 additions & 0 deletions src/main/scala/misc/codejam/srb/Cell.scala
@@ -0,0 +1,13 @@
package misc.codejam.srb

case class CellInfo(val ceiling:Int, val floor:Int, var isDone:Boolean) {
def isMovable(that:CellInfo):Boolean = {
if (that.ceiling - that.floor < 50) {
false
} else {
val diff1 = Math.abs(this.ceiling - that.floor);
val diff2 = Math.abs(this.floor - that.ceiling);
(Math.min(diff1,diff2) >= 50)
}
}
}
78 changes: 78 additions & 0 deletions src/main/scala/misc/codejam/srb/TideInTideOut.scala
@@ -0,0 +1,78 @@
package misc.codejam.srb
import scala.collection.mutable.ListBuffer

import misc.codejam.srb.CellInfo

object TideInTideOut {
val cave:Cave = null;

val direction = cave.getMovableDirection();

val (second, nextCave) = cave.moveTo(direction(0))


}
class Cave(val pos:(Int,Int), val height: Int, val cave: List[List[CellInfo]]) {
type Second = Int
type Height = Int

val (curX, curY) = pos
val curCell = cave(curY)(curX)

def getMovableDirection():List[(Int,Int)] = {
def checkMovable(x:Int, y:Int):Boolean ={
if (x> -1 && y> -1 && y< cave.size && x < cave(0).size) {
val to = cave(y)(x)
(!to.isDone) && (curCell.isMovable (to))
} else {
false
}
}
val movable:ListBuffer[(Int,Int)] = new ListBuffer();
// up
if (checkMovable(curX, curY-1)) movable+=((curX, curY-1))
// down
if (checkMovable(curX, curY+1)) movable+=((curX, curY+1))
// left
if (checkMovable(curX-1, curY)) movable+=((curX-1, curY))
// right
if (checkMovable(curX+1, curY)) movable+=((curX+1, curY))

movable.toList
}

def moveTo(pos:(Int,Int)):(Second, Cave) = {
val (x,y) = pos
curCell.isDone = true
val timeToMove = getTimeToMove(cave(y)(x))
val nextHeight = height - timeToMove * 10
(timeToMove, new Cave(pos, nextHeight, cave))
}

def getTimeToMove( to: CellInfo):Second = {
var currentHeight = height;

// wait time
val lowerCeiling = Math.min(to.ceiling, curCell.ceiling);
var waitSec = (currentHeight - (lowerCeiling - 50)) / 10
if (waitSec < 0) waitSec = 0
else {
currentHeight = Math.min(to.ceiling, curCell.ceiling) - 50
}

if (currentHeight - curCell.floor > 20) {
// water
waitSec + 1
} else {
// lands
waitSec + 10
}
}
}

object Test extends App {
// Console.println(TideInTideOut.getTimeToMove(150, CellInfo(200, 0), CellInfo(100, 0)));
// Console.println(TideInTideOut.getTimeToMove(150, CellInfo(200, 0), CellInfo(100, 80)));
// Console.println(TideInTideOut.getTimeToMove(100, CellInfo(200, 100), CellInfo(140, 0)));
// Console.println(TideInTideOut.getTimeToMove(150, CellInfo(300, 100), CellInfo(170, 0)));
}
5 changes: 5 additions & 0 deletions src/test/scala/misc/codejam/srb/CaveSpec.scala
@@ -0,0 +1,5 @@
package misc.codejam.srb

class CaveSpec extends {

}

0 comments on commit e92c375

Please sign in to comment.