parent
9e459a9d1d
commit
4c444e7978
@ -0,0 +1,4 @@
|
||||
.metals/
|
||||
.bloop/
|
||||
target/
|
||||
project/metals.sbt
|
@ -0,0 +1 @@
|
||||
version = "2.0.1"
|
@ -0,0 +1,8 @@
|
||||
name := "scala"
|
||||
|
||||
version := "0.1"
|
||||
|
||||
scalaVersion := "2.13.1"
|
||||
|
||||
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"
|
||||
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"
|
@ -0,0 +1 @@
|
||||
sbt.version = 1.3.3
|
@ -0,0 +1,78 @@
|
||||
package day1;
|
||||
|
||||
object Move extends Enumeration {
|
||||
type Move = Value
|
||||
val X, O, ? = Value
|
||||
}
|
||||
|
||||
object TicTacToe extends App{
|
||||
|
||||
println(winner(List(
|
||||
Move.?, Move.?, Move.?,
|
||||
Move.?, Move.?, Move.?,
|
||||
Move.?, Move.?, Move.?,
|
||||
)))
|
||||
|
||||
println(winner(List(
|
||||
Move.X, Move.O, Move.O,
|
||||
Move.O, Move.X, Move.O,
|
||||
Move.?, Move.?, Move.O,
|
||||
)))
|
||||
|
||||
println(winner(List(
|
||||
Move.X, Move.X, Move.X,
|
||||
Move.O, Move.X, Move.O,
|
||||
Move.?, Move.?, Move.O,
|
||||
)))
|
||||
|
||||
println(winner(List(
|
||||
Move.?, Move.X, Move.X,
|
||||
Move.O, Move.X, Move.O,
|
||||
Move.?, Move.?, Move.O
|
||||
)))
|
||||
|
||||
|
||||
def winner(board: List[Move.Move]): Move.Move = {
|
||||
val a1 :: a2 :: a3 :: b1 :: b2 :: b3 :: c1 :: c2 :: c3 :: _ = board
|
||||
|
||||
List(
|
||||
(a1, a2, a3),
|
||||
(b1, b2, b3),
|
||||
(c1, c2, c3),
|
||||
(a1, b1, c1),
|
||||
(a2, b2, c2),
|
||||
(a3, b3, c3),
|
||||
(a1, b2, c3),
|
||||
(a3, b2, c1),
|
||||
).find((rule) => {
|
||||
rule._1 == rule._2 && rule._1 == rule._3
|
||||
}).map(_._1)
|
||||
.getOrElse(Move.?)
|
||||
|
||||
}
|
||||
|
||||
winner(List(
|
||||
Move.?, Move.?, Move.?,
|
||||
Move.?, Move.?, Move.?,
|
||||
Move.?, Move.?, Move.?,
|
||||
))
|
||||
|
||||
winner(List(
|
||||
Move.X, Move.O, Move.O,
|
||||
Move.O, Move.X, Move.O,
|
||||
Move.?, Move.?, Move.O,
|
||||
))
|
||||
|
||||
winner(List(
|
||||
Move.X, Move.X, Move.X,
|
||||
Move.O, Move.X, Move.O,
|
||||
Move.?, Move.?, Move.O,
|
||||
))
|
||||
|
||||
winner(List(
|
||||
Move.?, Move.X, Move.X,
|
||||
Move.O, Move.X, Move.O,
|
||||
Move.?, Move.?, Move.O
|
||||
))
|
||||
|
||||
}
|
Loading…
Reference in new issue