-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Pla 982 add bestemshe #185
Changes from 7 commits
246468a
6e3fd15
e931425
f647b5e
5475d9c
2b65d97
23c42bb
1ebc712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package strategygames.togyzkumalak | ||
package variant | ||
|
||
import strategygames.togyzkumalak._ | ||
import strategygames.{ GameFamily, Player } | ||
|
||
case object Bestemshe | ||
extends Variant( | ||
id = 2, | ||
key = "bestemshe", | ||
name = "Bestemshe", | ||
standardInitialPosition = false, | ||
boardSize = Board.Dim5x2 | ||
) { | ||
|
||
def gameFamily: GameFamily = GameFamily.Togyzkumalak() | ||
|
||
def perfIcon: Char = '' | ||
def perfId: Int = 401 | ||
|
||
override def baseVariant: Boolean = false | ||
|
||
override def canOfferDraw = false | ||
|
||
// cache this rather than checking with the API everytime | ||
override def initialFen = | ||
format.FEN("5S,5S,5S,5S,5S/5S,5S,5S,5S,5S 0 0 S 1") | ||
|
||
override def usesTuzdik = false | ||
|
||
// TODO check legalMoves.size == 0 condition | ||
override def specialEnd(situation: Situation) = | ||
(situation.board.history.score.p1 > 25) || | ||
(situation.board.history.score.p2 > 25) || | ||
(situation.moves.size == 0) | ||
|
||
override def specialDraw(situation: Situation) = | ||
situation.board.history.score.p1 == situation.board.history.score.p2 | ||
|
||
override def winner(situation: Situation): Option[Player] = | ||
if (specialEnd(situation) && !specialDraw(situation)) { | ||
if (situation.board.history.score.p1 > situation.board.history.score.p2) | ||
Player.fromName("p1") | ||
else Player.fromName("p2") | ||
} else None | ||
|
||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -5,6 +5,7 @@ import org.specs2.matcher.ValidatedMatchers | |||
import org.specs2.mutable.Specification | ||||
|
||||
import strategygames.backgammon.format.Uci | ||||
import strategygames.backgammon.variant.Variant | ||||
|
||||
class BackgammonTest extends Specification with ValidatedMatchers { | ||||
|
||||
|
@@ -13,9 +14,13 @@ class BackgammonTest extends Specification with ValidatedMatchers { | |||
vg.flatMap { g => g.apply(action).map(_._1) } | ||||
} | ||||
|
||||
def playActionStrs(actionStrs: List[String], game: Option[Game] = None): Validated[String, Game] = | ||||
def playActionStrs( | ||||
actionStrs: List[String], | ||||
game: Option[Game] = None, | ||||
variant: Option[Variant] = None | ||||
): Validated[String, Game] = | ||||
playUciList( | ||||
game.getOrElse(Game.apply(variant.Backgammon)), | ||||
game.getOrElse(Game.apply(variant.getOrElse(Variant.default))), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a difference here between writing Game.apply(<some_param>) and Game(<some_param>) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both
Despite that being my personal preference, I don't think this standard is followed throughout the codebase and I have no problem with you doing either approach |
||||
Uci.readList(actionStrs.mkString(" ")).getOrElse(List()) | ||||
) | ||||
|
||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package strategygames.togyzkumalak | ||
|
||
import org.specs2.matcher.ValidatedMatchers | ||
|
||
import strategygames.{ Player, Score } | ||
|
||
import strategygames.togyzkumalak.variant.Bestemshe | ||
|
||
class BestemsheVariantTest extends TogyzkumalakTest with ValidatedMatchers { | ||
|
||
"valid moves in initial situation" should { | ||
val board = Board.init(Bestemshe) | ||
val situation = Situation(board, Player.P1) | ||
|
||
val moves = Bestemshe.validMoves(situation) | ||
"be valid" in { | ||
moves.size must_== 5 | ||
} | ||
} | ||
|
||
"valid opening moves" should { | ||
"valid situation after first move" in { | ||
playActionStrs(List("c1d2"), variant = Some(Bestemshe)) must beValid.like { g => | ||
g.situation.player must_== Player.P2 | ||
g.situation.moves.size must_== 4 | ||
g.situation.board.history.score must_== Score(6, 0) | ||
g.situation.end must_== false | ||
} | ||
} | ||
"valid situation after first two moves" in { | ||
playActionStrs(List("c1d2", "c2b1"), variant = Some(Bestemshe)) must beValid.like { g => | ||
g.situation.player must_== Player.P1 | ||
g.situation.moves.size must_== 4 | ||
g.situation.board.history.score must_== Score(6, 6) | ||
} | ||
} | ||
} | ||
|
||
// no tuzdik created | ||
// "tuzdik rules are respected" should { | ||
// val actionStrs = List("f1e2", "d2e1", "i1a2", "b2i1", "b1g2", "f2e1") | ||
// "no tuzdiks initially" in { | ||
// playActionStrs(actionStrs.dropRight(1)) must beValid.like { g => | ||
// g.situation.player must_== Player.P2 | ||
// g.situation.board.pieces.filter { | ||
// case (_, (p, _)) if p.role == Tuzdik => true; case _ => false | ||
// }.size must_== 0 | ||
// g.situation.board.pieces(Pos.E1) must_== ((Piece(Player.P1, Stone), 2)) | ||
// g.situation.board.history.score must_== Score(22, 12) | ||
// } | ||
// } | ||
// "tuzdik created when landing on space with 2 stones" in { | ||
// playActionStrs(actionStrs) must beValid.like { g => | ||
// g.situation.player must_== Player.P1 | ||
// g.situation.board.pieces | ||
// .filter { | ||
// case (_, (p, _)) if p.role == Tuzdik => true; case _ => false | ||
// } must_== Map(Pos.E1 -> ((Piece(Player.P2, Tuzdik), 1))) | ||
// g.situation.board.history.score must_== Score(22, 15) | ||
// } | ||
// } | ||
// } | ||
|
||
// "game ends properly" should { | ||
// // https://playstrategy.org/FgWSk5be | ||
// val actionStrs = List( | ||
// ) | ||
// "when a player has > 25 stones" in { | ||
// playActionStrs(actionStrs) must beValid.like { g => | ||
// g.situation.end must_== true | ||
// g.situation.winner must_== Some(Player.P1) | ||
// g.situation.board.history.score must_== Score(82, 43) | ||
// } | ||
// } | ||
// } | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you want to change this to false ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured best to leave this clause in (which wont be triggered with regular Bestemshe) but when we get to the point where we are offering FromPosition for all variants then it could be possible to create a position (fen) where the scores start as odd and so a draw is possible. if i remove this code then i think it will just look in
winner
and award p2 as a winner in these 'tie' situations.