summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobby Zambito <Zambito101@gmail.com>2019-11-26 22:47:11 -0500
committerRobby Zambito <Zambito101@gmail.com>2019-11-26 22:47:11 -0500
commit8d8ad90c857e6db91c49b7e464f64382a55e9e4d (patch)
tree131245871e54e1b5ad1317b7d8bd9cb53ad1fac8
parent14a9cdd3c54e310936d3ccd722d8e846bb01c026 (diff)
Made sure to remove duplicate taken positions. Broke move score into its own implicit method.
-rw-r--r--.idea/sbt.xml1
-rw-r--r--.idea/scala_compiler.xml4
-rw-r--r--build.sbt7
-rw-r--r--project/build.properties4
-rw-r--r--src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala9
-rw-r--r--src/main/scala/me/robbyzambito/othello/game/Player.scala12
6 files changed, 29 insertions, 8 deletions
diff --git a/.idea/sbt.xml b/.idea/sbt.xml
index 1bf561c..5903c57 100644
--- a/.idea/sbt.xml
+++ b/.idea/sbt.xml
@@ -12,6 +12,7 @@
<option value="$PROJECT_DIR$/project" />
</set>
</option>
+ <option name="sbtVersion" value="1.3.3" />
<option name="useQualifiedModuleNames" value="true" />
</SbtProjectSettings>
</option>
diff --git a/.idea/scala_compiler.xml b/.idea/scala_compiler.xml
index 8fdaf03..a26a233 100644
--- a/.idea/scala_compiler.xml
+++ b/.idea/scala_compiler.xml
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ScalaCompilerConfiguration">
- <profile name="sbt 1" modules="OthelloAI">
- <option name="implicitConversions" value="true" />
- </profile>
+ <profile name="sbt 1" modules="OthelloAI" />
</component>
</project> \ No newline at end of file
diff --git a/build.sbt b/build.sbt
index 733f818..2d4bb60 100644
--- a/build.sbt
+++ b/build.sbt
@@ -3,3 +3,10 @@ name := "OthelloAI"
version := "0.1"
scalaVersion := "2.13.1"
+
+mappings in (Compile, packageSrc) ++= {
+ import Path.{flat, relativeTo}
+ val base = (sourceManaged in Compile).value
+ val srcs = (managedSources in Compile).value
+ srcs pair (relativeTo(base) | flat)
+}
diff --git a/project/build.properties b/project/build.properties
index 010613d..7ebd936 100644
--- a/project/build.properties
+++ b/project/build.properties
@@ -1 +1,3 @@
-sbt.version = 1.3.3 \ No newline at end of file
+sbt.version = 1.3.3
+
+addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10") \ No newline at end of file
diff --git a/src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala b/src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala
index c09d172..4fbb2d9 100644
--- a/src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala
+++ b/src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala
@@ -11,13 +11,16 @@ package me.robbyzambito.othello.game
*/
case class AIPlayer(override val color: Position) extends Player(color) {
+ implicit class MoveScore(m: Move) {
+ def score: Int = m.takenPositions.length
+ }
+
override def nextMove(board: Board): Move = {
- implicit val moveOrdering: Ordering[Move] =
- (x, y) => x.takenPositions.length.compareTo(y.takenPositions.length)
+ implicit val moveOrdering: Ordering[Move] = (x, y) => x.score.compareTo(y.score)
println(s"$this moving...")
- Thread.sleep(500L)
+ Thread.sleep(1000L)
println()
possibleMoves(board).max
diff --git a/src/main/scala/me/robbyzambito/othello/game/Player.scala b/src/main/scala/me/robbyzambito/othello/game/Player.scala
index 925f7d2..c55f6db 100644
--- a/src/main/scala/me/robbyzambito/othello/game/Player.scala
+++ b/src/main/scala/me/robbyzambito/othello/game/Player.scala
@@ -13,6 +13,15 @@ import scala.util.Try
* @param color The color of the player.
*/
abstract class Player(val color: Position) {
+
+ /**
+ * The players decision on where to move based on
+ * the current board. It is assumed that there is
+ * at least one valid move.
+ *
+ * @param board
+ * @return
+ */
def nextMove(board: Board): Move
def canMove(board: Board): Boolean =
@@ -85,7 +94,8 @@ abstract class Player(val color: Position) {
Some(
Move(rowCount,
colCount,
- acc.map(_.takenPositions).getOrElse(List.empty) ::: vert.map(_.takenPositions).getOrElse(List.empty))
+ (acc.map(_.takenPositions).getOrElse(List.empty) :::
+ vert.map(_.takenPositions).getOrElse(List.empty)).distinct)
)
else None
}).flatten