Skip to content

Instantly share code, notes, and snippets.

@toshikazuhorii
Forked from seratch/gist:1108560
Created July 27, 2011 10:54
Show Gist options
  • Save toshikazuhorii/1109141 to your computer and use it in GitHub Desktop.
Save toshikazuhorii/1109141 to your computer and use it in GitHub Desktop.
Daimon.scala #8 やってみよう
/**
* Daimon.scala #8 やってみよう
* http://d.hatena.ne.jp/seratch2/20110507/1304777166
* 以下のPlayer、Gameをそれぞれアクターとして定義して山手線ゲームをコメント例のように実行できるようにしてください。
*/
import actors.Actor
class Get
case class IsUsed(station: Station)
case class MarkAsUsed(station: Station)
case class MarkAsUsedResponse(isMarkedAsUsed: Boolean)
case class Station(name: String)
class Yamanotesen extends Actor {
start()
def act() = loop {
react {
case _: Get => sender ! station
case IsUsed(station) => sender ! used.contains(station)
case MarkAsUsed(station) => {
used += station
sender ! MarkAsUsedResponse(used.contains(station))
}
case _ => throw new IllegalArgumentException
}
}
def station: Station = {
stations(new java.util.Random().nextInt(stations.length-1))
}
private val stations: List[Station] = List(
Station("東京")
,Station("有楽町")
,Station("新橋")
,Station("浜松町")
,Station("田町")
,Station("品川")
,Station("大崎")
,Station("五反田")
,Station("目黒")
,Station("恵比寿")
,Station("渋谷")
,Station("原宿")
,Station("代々木")
,Station("新宿")
,Station("新大久保")
,Station("高田馬場")
,Station("目白")
,Station("池袋")
,Station("大塚")
,Station("巣鴨")
,Station("駒込")
,Station("田端")
,Station("西日暮里")
,Station("日暮里")
,Station("御徒町")
,Station("秋葉原")
,Station("神田")
)
import collection.mutable.{Set,HashSet}
private var used: Set[Station] = new HashSet[Station]
}
// TODO Player、Gameを実装する
class Start
val Andy = new Player("Andy")
val Brian = new Player("Brian")
new Game(Andy,Brian) ! new Start
Thread.sleep(5000L)
System.exit(0)
/*
パンパン!
Andy「浜松町」
パンパン!
Brian「日暮里」
パンパン!
Andy「大塚」
パンパン!
Brian「目白」
パンパン!
Andy「品川」
パンパン!
Brian「恵比寿」
パンパン!
Andy「日暮里・・あっ!」
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment