Skip to content

Commit 1eec95e

Browse files
authored
Merge pull request #200 from Mind-Sports-Games/pla-1039-add-hyper-backgammon-variant
add new variant hyper backgammon
2 parents 20c141e + 9055d87 commit 1eec95e

File tree

4 files changed

+110
-10
lines changed

4 files changed

+110
-10
lines changed

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name := "strategygames"
22

33
organization := "org.playstrategy"
44

5-
version := "10.2.1-pstrat162"
5+
version := "10.2.1-pstrat163"
66

77
scalaVersion := "2.13.10"
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package strategygames.backgammon
2+
package variant
3+
4+
import strategygames.backgammon._
5+
import strategygames.GameFamily
6+
7+
case object Hyper
8+
extends Variant(
9+
id = 4,
10+
key = "hyper",
11+
name = "Hyper",
12+
standardInitialPosition = false,
13+
boardSize = Board.Dim12x2
14+
) {
15+
16+
def gameFamily: GameFamily = GameFamily.Backgammon()
17+
18+
def perfIcon: Char = ''
19+
def perfId: Int = 602
20+
21+
override def numStartingPiecesPerPlayer: Int = 3
22+
23+
// gammon and backgammon only count when the cube has been doubled in this variant
24+
override def gammonWin(situation: Situation) = false
25+
override def backgammonWin(situation: Situation) = false
26+
27+
override def baseVariant: Boolean = false
28+
29+
override def initialFen =
30+
format.FEN("9,1S,1S,1S/9,1s,1s,1s[] - - w 0 0 1")
31+
32+
}

src/main/scala/backgammon/variant/Variant.scala

+12-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ abstract class Variant private[variant] (
4848

4949
def startPlayer: Player = P1
5050

51+
def numStartingPiecesPerPlayer: Int = 15
52+
5153
// returns the updated piecemap for pieces on the board and an optional captured piece to put in the pocket
5254
private def piecesAfterAction(
5355
pieces: PieceMap,
@@ -479,8 +481,8 @@ abstract class Variant private[variant] (
479481
else None
480482

481483
def specialEnd(situation: Situation) =
482-
(situation.board.history.score.p1 == 15) ||
483-
(situation.board.history.score.p2 == 15)
484+
(situation.board.history.score.p1 == numStartingPiecesPerPlayer) ||
485+
(situation.board.history.score.p2 == numStartingPiecesPerPlayer)
484486

485487
def gammonPosition(situation: Situation, player: Player) =
486488
situation.board.history.score(player) == 0 &&
@@ -489,8 +491,8 @@ abstract class Variant private[variant] (
489491

490492
// doesnt check for not a backgammonWin
491493
def gammonWin(situation: Situation) =
492-
(situation.board.history.score.p1 == 15 && situation.board.history.score.p2 == 0) ||
493-
(situation.board.history.score.p2 == 15 && situation.board.history.score.p1 == 0)
494+
(situation.board.history.score.p1 == numStartingPiecesPerPlayer && situation.board.history.score.p2 == 0) ||
495+
(situation.board.history.score.p2 == numStartingPiecesPerPlayer && situation.board.history.score.p1 == 0)
494496

495497
def backgammonPosition(situation: Situation, player: Player) =
496498
situation.board.history.score(player) == 0 &&
@@ -499,12 +501,12 @@ abstract class Variant private[variant] (
499501

500502
def backgammonWin(situation: Situation) =
501503
(
502-
situation.board.history.score.p1 == 15 &&
504+
situation.board.history.score.p1 == numStartingPiecesPerPlayer &&
503505
situation.board.history.score.p2 == 0 && (
504506
situation.board.piecesOnBar(P2) || situation.board.pieceInOpponentsHome(P2)
505507
)
506508
) || (
507-
situation.board.history.score.p2 == 15 &&
509+
situation.board.history.score.p2 == numStartingPiecesPerPlayer &&
508510
situation.board.history.score.p1 == 0 && (
509511
situation.board.piecesOnBar(P1) || situation.board.pieceInOpponentsHome(P1)
510512
)
@@ -521,8 +523,8 @@ abstract class Variant private[variant] (
521523
def materialImbalance(board: Board): Int = board.history.score.p2 - board.history.score.p1
522524

523525
def valid(board: Board, @nowarn strict: Boolean): Boolean =
524-
board.playerPiecesOnBoardOrInPocket(P1) + board.history.score.p1 == 15 &&
525-
board.playerPiecesOnBoardOrInPocket(P2) + board.history.score.p2 == 15
526+
board.playerPiecesOnBoardOrInPocket(P1) + board.history.score.p1 == numStartingPiecesPerPlayer &&
527+
board.playerPiecesOnBoardOrInPocket(P2) + board.history.score.p2 == numStartingPiecesPerPlayer
526528

527529
val roles: List[Role] = Role.all
528530

@@ -549,7 +551,8 @@ object Variant {
549551

550552
lazy val all: List[Variant] = List(
551553
Backgammon,
552-
Nackgammon
554+
Nackgammon,
555+
Hyper
553556
)
554557
val byId = all map { v =>
555558
(v.id, v)

src/test/scala/backgammon/BackgammonVariantTest.scala

+65
Original file line numberDiff line numberDiff line change
@@ -4988,8 +4988,73 @@ class BackgammonVariantTest extends BackgammonTest with ValidatedMatchers {
49884988
g.situation.forcedAction.isEmpty must_== true
49894989
}
49904990
}
4991+
}
4992+
4993+
"A Hyper Backgammon game " should {
4994+
"have 3 moves from start" in {
4995+
val actionStrs = List(
4996+
"4/2",
4997+
"l1h1"
4998+
)
4999+
playActionStrs(actionStrs, Some(Game.apply(variant.Hyper))) must beValid.like { g =>
5000+
g.situation.moves.values.flatten.map(_.toUci.uci).toSet must_== Set("h1f1", "j1h1", "k1i1")
5001+
}
5002+
}
49915003

5004+
"end in single win even if in backgammon position" in {
5005+
val actionStrs = List(
5006+
"endturn",
5007+
"6/2",
5008+
"l1j1",
5009+
"k1e1",
5010+
"endturn",
5011+
"3/1",
5012+
"l2i2",
5013+
"j2i2",
5014+
"endturn",
5015+
"4/4",
5016+
"j1f1",
5017+
"f1b1",
5018+
"b1c2",
5019+
"c2g2",
5020+
"endturn",
5021+
"6/4",
5022+
"k2e2",
5023+
"e2a2",
5024+
"endturn",
5025+
"6/6",
5026+
"e1b2",
5027+
"b2h2",
5028+
"j1d1",
5029+
"d1c2",
5030+
"endturn",
5031+
"2/1",
5032+
"a2a1",
5033+
"a1c1",
5034+
"endturn",
5035+
"5/5",
5036+
"c2h2",
5037+
"g2l2",
5038+
"^h2",
5039+
"^h2",
5040+
"endturn",
5041+
"2/1",
5042+
"c1d1",
5043+
"d1f1",
5044+
"endturn",
5045+
"1/2",
5046+
"^l2"
5047+
)
5048+
playActionStrs(actionStrs, Some(Game.apply(variant.Hyper))) must beValid.like { g =>
5049+
g.situation.board.history.score must_== Score(0, 3)
5050+
g.situation.end must_== true
5051+
g.situation.board.pieceInOpponentsHome(Player.P1) must_== true
5052+
g.situation.winner must_== Some(Player.P2)
5053+
g.situation.status must_== Some(Status.SingleWin) // not a backgammon due to no double of cube
5054+
}
5055+
}
49925056
}
5057+
49935058
}
49945059

49955060
class BackgammonVariantTestIsometry extends strategygames.chess.ChessTest {

0 commit comments

Comments
 (0)