-
Notifications
You must be signed in to change notification settings - Fork 0
/
UciEngineVsItself.scala
58 lines (52 loc) · 2.16 KB
/
UciEngineVsItself.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Equites, a Scala chess playground
// Copyright © 2013 Frank S. Thomas <frank@timepit.eu>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package eu.timepit.equites
package cli
import scala.concurrent.duration._
import scalaz.concurrent.Task
import scalaz.stream._
import proto.Uci._
import proto.UciProcess._
import util.ScalazProcess._
/*
object UciEngineVsItself extends App {
val game = os.spawnCmd("gnuchess", "-u").flatMap(_.proc).flatMap { engine =>
val readResponses =
engine.stdOut.pipe(os.linesIn).pipe(collectResponses)
val readFirstBestmove =
readResponses.repeat.once.collectFirst { case bm: Bestmove => bm }
def writePositionCommand(history: Seq[GameState]) =
toRawCommands(Position(history)).pipe(os.linesOut).through(engine.stdIn)
val writeGoCommand =
toRawCommands(Go(Go.Movetime(10.millis))).pipe(os.linesOut).through(engine.stdIn)
val prepareGame: Process[Task, Any] =
newGameCommands.pipe(os.linesOut).through(engine.stdIn) ++ readResponses.find(_ == ReadyOk).repeat.once
val quitEngine =
toRawCommands(Quit).pipe(os.linesOut).through(engine.stdIn)
def gameLoop(history: Seq[GameState]): Process[Task, Seq[GameState]] =
writePositionCommand(history)
.append(writeGoCommand)
.drain
.append(Process(history).zip(readFirstBestmove) |> appendBestmove)
.observe(stdOutLastBoard)
.flatMap(gameLoop)
val initialPosition = Vector(GameState.init)
(prepareGame ++ gameLoop(initialPosition)).onComplete(quitEngine)
}
println("running process")
game.run.run
}
*/