Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validMoves and boardAfter #188

Draft
wants to merge 26 commits into
base: 503-abalone
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5d63998
feat: moves of 2 marbles
vincentfrochot Oct 21, 2024
033fd13
chore: codestyle
vincentfrochot Oct 21, 2024
471f1bc
feat: generate movesOf2 based on pairs of marbles
vincentfrochot Oct 21, 2024
2fc34c9
feat: generate validMoves
vincentfrochot Oct 23, 2024
b8a3c35
chore: move sideMoves methods under parent one
vincentfrochot Oct 23, 2024
8d08872
chore: use dropRight on List
vincentfrochot Oct 23, 2024
17357a6
chore: map(func) equals map(func(_))
vincentfrochot Oct 23, 2024
70b3abd
chore: situation.board.piecesOf(x) as val
vincentfrochot Oct 23, 2024
832dc59
chore: codestyle & reword some tests
vincentfrochot Oct 23, 2024
14b016e
chore: codestyle - direction can be computed from 2 Pos
vincentfrochot Oct 23, 2024
ece31e5
chore: refactor side moves
vincentfrochot Oct 24, 2024
d8f559b
chore: improve codestyle
vincentfrochot Oct 24, 2024
763e0db
feat: boardAfter
vincentfrochot Oct 25, 2024
ef24f2e
chore: use Directions instead of Option[String]
vincentfrochot Oct 25, 2024
6b42fcb
chore: remove done TODO
vincentfrochot Oct 25, 2024
e5f54a4
feat: 3fold, improve codestyle
vincentfrochot Oct 29, 2024
c75eea8
chore: codestyle Variant.piecesAfterAction
vincentfrochot Oct 29, 2024
93be03b
fix: Game make use of metrics
vincentfrochot Oct 29, 2024
8e3b9dc
chore: remove copy pasted false comment
vincentfrochot Oct 29, 2024
3e2f3be
fix: get rid of autoEndTurn in Move
vincentfrochot Oct 29, 2024
cfc8552
fix: revert autoEndTurn to get it back
vincentfrochot Oct 29, 2024
182321a
fix: side moves pieceMap update
vincentfrochot Oct 29, 2024
92d5961
feat: remove move cat in validMovesOf2And3
vincentfrochot Oct 29, 2024
69066c6
chore: remove unused dir as String methods
vincentfrochot Oct 29, 2024
4d85c75
feat: update PieceMap based on 2 Pos only
vincentfrochot Oct 30, 2024
98de331
feat: replayMove invoke boardAfter
vincentfrochot Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/scala/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ object Game {
partialCaptures: Boolean = false
): Validated[String, (Game, Move)] = (orig, dest) match {
case (Pos.Abalone(orig), Pos.Abalone(dest)) =>
g.apply(orig, dest, None, metrics)
g.apply(orig, dest, metrics)
.toEither
.map(t => (Abalone(t._1), Move.Abalone(t._2)))
.toValidated
Expand Down Expand Up @@ -1278,7 +1278,7 @@ object Game {
sys.error("Can't diceroll in Abalone")

def undo(metrics: MoveMetrics = MoveMetrics()): Validated[String, (Game, Undo)] =
sys.error("Can't undo in abalone")
sys.error("Can't undo in abalone") // @TODO: might want to be able to undo, actually

def endTurn(metrics: MoveMetrics = MoveMetrics()): Validated[String, (Game, EndTurn)] =
sys.error("Can't endTurn in abalone")
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Move.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ object Move {
Pos.Abalone(m.dest),
Situation.Abalone(m.situationBefore),
Board.Abalone(m.after),
m.autoEndTurn,
false,
None, // capture. @TODO: Could be the pos of the piece that was on targetSquare described by the move (because line moves (and by extension, pushes) are basically just marbles jumping over other ones)
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Situation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ object Situation {
partialCaptures: Boolean = false
): Validated[String, Move] = (from, to) match {
case (Pos.Abalone(from), Pos.Abalone(to)) =>
s.move(from, to, promotion.map(_.toAbalone)).toEither.map(m => Move.Abalone(m)).toValidated
s.move(from, to).toEither.map(m => Move.Abalone(m)).toValidated
case _ => sys.error("Not passed Abalone objects")
}

Expand Down
4 changes: 4 additions & 0 deletions src/main/scala/abalone/Board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ case class Board(

def piecesOf(player: Player): PieceMap = pieces.filter(_._2.is(player))

def isEmptySquare(pos: Option[Pos]): Boolean = pos.fold(false)(!this.pieces.contains(_))

def withHistory(h: History): Board = copy(history = h)
def updateHistory(f: History => History) = copy(history = f(history))

Expand All @@ -33,6 +35,8 @@ case class Board(

def materialImbalance: Int = variant.materialImbalance(this)

def autoDraw: Boolean = history.threefoldRepetition && variant.repetitionEnabled

override def toString = s"$variant Position after ${history.recentTurnUciString}"

lazy val actors: Map[Pos, Actor] = pieces.map {
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/abalone/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ case class Game(
def apply(
orig: Pos,
dest: Pos,
promotion: Option[PromotableRole] = None,
metrics: MoveMetrics = MoveMetrics()
): Validated[String, (Game, Move)] =
situation.move(orig, dest, promotion).map(_ withMetrics metrics) map { move =>
situation.move(orig, dest).map(_ withMetrics metrics) map { move =>
apply(move) -> move
}

Expand All @@ -38,7 +37,7 @@ case class Game(
}

def apply(uci: Uci.Move): Validated[String, (Game, Move)] =
apply(uci.orig, uci.dest, uci.promotion)
apply(uci.orig, uci.dest)

private def applyClock(metrics: MoveMetrics, gameActive: Boolean, switchClock: Boolean) =
clock.map { c =>
Expand Down
Loading