Created
December 8, 2014 21:24
-
-
Save MatMoore/552096b5580a39c4f3a1 to your computer and use it in GitHub Desktop.
West London Hack Night December 2014
This file contains hidden or 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
/** | |
* Created by mat on 08/12/2014. | |
*/ | |
import java.net._ | |
import java.io.{Console => _, _} | |
import scala.collection.mutable | |
import scala.io._ | |
object RDCP extends App { | |
val mazeSock = new Socket(InetAddress.getByName("10.112.156.136"), 8080) | |
lazy val inLines = new BufferedSource(mazeSock.getInputStream()).getLines() | |
val out = new PrintStream(mazeSock.getOutputStream()) | |
Console.println("Hello Reindeer") | |
val language = """Language.*""".r | |
val directions = """N(\d+) E(\d+) S(\d+) W(\d+) P([XNESW?])""".r | |
var decisions = new mutable.HashMap[(Int,Int,Int,Int,String),Int]() | |
def getNextStep(n: Int, e: Int, s: Int, w: Int, p: String): Tuple2[String, Int] = { | |
val win = """X""".r | |
val news = """([NEWS])""".r | |
val donotsee = """\?""".r | |
p match { | |
case win() => { | |
Console.println("VICTORY!") | |
} | |
case news(dir) => return (dir,1) | |
case donotsee() => { | |
if (n>0) { return ("N",n)} | |
if (s>0) { return ("S",s)} | |
if (e>0) { return ("E",e)} | |
if (w>0) { return ("W",w)} | |
} | |
case _ => {} | |
} | |
Console.println(n,e,s,w,p) | |
new Tuple2("N", 1) | |
} | |
while(inLines.hasNext) { | |
val lineIn = inLines.next() | |
Console.println(lineIn) | |
lineIn match { | |
case language() => { | |
out.println("ParseThePacket") | |
Console.println("ParseThePacket") | |
} | |
case directions(n,e,s,w,p) => { | |
val tuple = getNextStep(n.toInt, e.toInt, s.toInt, w.toInt, p) | |
Console.println(s"Dir ${tuple._1} Far ${tuple._2}") | |
out.println(s"${tuple._1}") | |
} | |
case _ => {Console.println("wat")} | |
} | |
} | |
Console.println("Hello Reindeer") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment