Browse Source

Made sure to remove duplicate taken positions. Broke move score into its own implicit method.

recursive-to-for
Robby Zambito 7 months ago
parent
commit
8d8ad90c85
6 changed files with 29 additions and 8 deletions
  1. +1
    -0
      .idea/sbt.xml
  2. +1
    -3
      .idea/scala_compiler.xml
  3. +7
    -0
      build.sbt
  4. +3
    -1
      project/build.properties
  5. +6
    -3
      src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala
  6. +11
    -1
      src/main/scala/me/robbyzambito/othello/game/Player.scala

+ 1
- 0
.idea/sbt.xml View File

@@ -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>


+ 1
- 3
.idea/scala_compiler.xml View File

@@ -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>

+ 7
- 0
build.sbt View File

@@ -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)
}

+ 3
- 1
project/build.properties View File

@@ -1 +1,3 @@
sbt.version = 1.3.3
sbt.version = 1.3.3

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

+ 6
- 3
src/main/scala/me/robbyzambito/othello/game/AIPlayer.scala View File

@@ -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


+ 11
- 1
src/main/scala/me/robbyzambito/othello/game/Player.scala View File

@@ -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


Loading…
Cancel
Save