Skip to content

Commit 731eded

Browse files
committed
feat: removed fivefold repetition, condensed to twenty-five move rule
1 parent 58fa431 commit 731eded

File tree

2 files changed

+13
-73
lines changed

2 files changed

+13
-73
lines changed

game.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,12 @@ const (
4040
DrawOffer
4141
// Stalemate indicates that the game was drawn by stalemate.
4242
Stalemate
43-
// ThreefoldRepetition indicates that the game was drawn when the game
44-
// state was repeated three times and a player requested a draw.
43+
// ThreefoldRepetition indicates that the game was automatically drawn
44+
// by the game state being repeated three times.
4545
ThreefoldRepetition
46-
// FivefoldRepetition indicates that the game was automatically drawn
47-
// by the game state being repeated five times.
48-
FivefoldRepetition
49-
// FiftyMoveRule indicates that the game was drawn by the half
50-
// move clock being one hundred or greater when a player requested a draw.
51-
FiftyMoveRule
52-
// SeventyFiveMoveRule indicates that the game was automatically drawn
53-
// when the half move clock was one hundred and fifty or greater.
54-
SeventyFiveMoveRule
46+
// TwentyFiveMoveRule indicates that the game was automatically drawn
47+
// when the half move clock was fifty or greater.
48+
TwentyFiveMoveRule
5549
// InsufficientMaterial indicates that the game was automatically drawn
5650
// because there was insufficient material for checkmate.
5751
InsufficientMaterial
@@ -267,10 +261,6 @@ func (g *Game) Draw(method Method) error {
267261
if g.numRepetitions() < 3 {
268262
return errors.New("octad: draw by ThreefoldRepetition requires at least three repetitions of the current board state")
269263
}
270-
case FiftyMoveRule:
271-
if g.pos.halfMoveClock < 100 {
272-
return fmt.Errorf("octad: draw by FiftyMoveRule requires the half move clock to be at 100 or greater but is %d", g.pos.halfMoveClock)
273-
}
274264
case DrawOffer:
275265
default:
276266
return fmt.Errorf("octad: unsupported draw method %s", method.String())
@@ -300,9 +290,6 @@ func (g *Game) EligibleDraws() []Method {
300290
if g.numRepetitions() >= 3 {
301291
draws = append(draws, ThreefoldRepetition)
302292
}
303-
if g.pos.halfMoveClock >= 100 {
304-
draws = append(draws, FiftyMoveRule)
305-
}
306293
return draws
307294
}
308295

@@ -363,15 +350,15 @@ func (g *Game) updatePosition() {
363350
}
364351

365352
// five fold rep creates automatic draw
366-
if !g.ignoreAutomaticDraws && g.numRepetitions() >= 5 {
353+
if !g.ignoreAutomaticDraws && g.numRepetitions() >= 3 {
367354
g.outcome = Draw
368-
g.method = FivefoldRepetition
355+
g.method = ThreefoldRepetition
369356
}
370357

371358
// 75 move rule creates automatic draw
372-
if !g.ignoreAutomaticDraws && g.pos.halfMoveClock >= 150 && g.method != Checkmate {
359+
if !g.ignoreAutomaticDraws && g.pos.halfMoveClock >= 50 && g.method != Checkmate {
373360
g.outcome = Draw
374-
g.method = SeventyFiveMoveRule
361+
g.method = TwentyFiveMoveRule
375362
}
376363

377364
// insufficient material creates automatic draw

game_test.go

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -158,55 +158,8 @@ func TestInvalidThreeFoldRepetition(t *testing.T) {
158158
}
159159
}
160160

161-
func TestFiveFoldRepetition(t *testing.T) {
162-
g, err := NewGame()
163-
if err != nil {
164-
t.Fatalf(err.Error())
165-
return
166-
}
167-
moves := []string{
168-
"Nc2", "Nb3", "Na1", "Nd4",
169-
"Nc2", "Nb3", "Na1", "Nd4",
170-
"Nc2", "Nb3", "Na1", "Nd4",
171-
"Nc2", "Nb3", "Na1", "Nd4",
172-
"Nc2", "Nb3", "Na1", "Nd4",
173-
}
174-
for _, m := range moves {
175-
if err = g.MoveStr(m); err != nil {
176-
t.Fatal(err)
177-
}
178-
}
179-
if g.Outcome() != Draw || g.Method() != FivefoldRepetition {
180-
t.Fatal("game: should automatically draw after five repetitions")
181-
}
182-
}
183-
184-
func TestFiftyMoveRule(t *testing.T) {
185-
ofen, _ := OFEN("n2k/4/3K/N3 b - - 100 60")
186-
g, err := NewGame(ofen)
187-
if err != nil {
188-
t.Fatalf(err.Error())
189-
return
190-
}
191-
if err := g.Draw(FiftyMoveRule); err != nil {
192-
t.Fatal(err)
193-
}
194-
}
195-
196-
func TestInvalidFiftyMoveRule(t *testing.T) {
197-
ofen, _ := OFEN("n2k/4/3K/N3 b - - 99 60")
198-
g, err := NewGame(ofen)
199-
if err != nil {
200-
t.Fatalf(err.Error())
201-
return
202-
}
203-
if err = g.Draw(FiftyMoveRule); err == nil {
204-
t.Fatal("game: should require fifty moves")
205-
}
206-
}
207-
208-
func TestSeventyFiveMoveRule(t *testing.T) {
209-
ofen, _ := OFEN("n2k/4/3K/N3 b - - 149 80")
161+
func TestTwentyFiveMoveRule(t *testing.T) {
162+
ofen, _ := OFEN("n2k/4/3K/N3 b - - 49 24")
210163
g, err := NewGame(ofen)
211164
if err != nil {
212165
t.Fatalf(err.Error())
@@ -215,8 +168,8 @@ func TestSeventyFiveMoveRule(t *testing.T) {
215168
if err = g.MoveStr("Kc4"); err != nil {
216169
t.Fatal(err)
217170
}
218-
if g.Outcome() != Draw || g.Method() != SeventyFiveMoveRule {
219-
t.Fatal("game: should automatically draw after seventy five moves w/ no pawn move or capture")
171+
if g.Outcome() != Draw || g.Method() != TwentyFiveMoveRule {
172+
t.Fatal("game: should automatically draw after twenty five moves w/ no pawn move or capture")
220173
}
221174
}
222175

0 commit comments

Comments
 (0)