1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
use rand::Rng;
use crate::{
core::{Color, GameStatus, Move, Piece, Position, Variant, VariantBuilder},
errors::{Chess960SPIDError, FenError, MoveError, PGNError},
logic::Game,
parsing::{
fen::{get_fen_from_chess960_spid, get_minified_fen},
pgn::{parse_multiple_pgn, parse_pgn},
},
utils::os::{read_file, write_file},
};
/// Chess960 is a variant of chess that uses the same rules as [standard chess](crate::variants::StandardChess), but the starting position of the pieces is randomized.
///
/// # Attributes
/// * `game` - The [Game] struct that contains the current state of the game
///
#[derive(Debug, Clone)]
pub struct Chess960 {
/// The [Game] struct that contains the current state of the game
game: Game,
}
impl Chess960 {
pub fn from_spid(spid: u16) -> Result<Chess960, Chess960SPIDError> {
let fen = get_fen_from_chess960_spid(spid)?;
let mut game = Game::from_fen(fen.as_str()).unwrap();
game.history.variant = Some("Chess960".to_string());
Ok(Chess960 { game })
}
}
impl Default for Chess960 {
/// Generates a random starting position for the pieces
///
/// # Returns
/// A [Chess960] struct with a random starting position
///
/// # Example
/// ```
/// # use chess_lab::variants::Chess960;
/// let variant = Chess960::default();
/// ```
///
fn default() -> Chess960 {
let spid: u16 = rand::thread_rng().gen_range(0..960);
Chess960::from_spid(spid).unwrap()
}
}
impl VariantBuilder for Chess960 {
/// Returns the name of the [Variant]
///
/// # Returns
/// A string with the name of the [Variant]
///
/// # Example
/// ```
/// # use chess_lab::core::VariantBuilder;
/// # use chess_lab::variants::Chess960;
/// let name = Chess960::name();
/// assert_eq!(name, "Chess960");
/// ```
///
fn name() -> &'static str {
"Chess960"
}
/// Returns a new instance of the variant from a [Game] struct
///
/// # Arguments
/// * `game` - The [Game] struct that contains the current state of the game
///
/// # Returns
/// A Chess960 struct with the game state
///
/// # Example
/// ```
/// # use chess_lab::core::VariantBuilder;
/// # use chess_lab::variants::Chess960;
/// use chess_lab::logic::Game;
///
/// let game = Game::default();
/// let variant = Chess960::new(game);
/// ```
///
fn new(game: Game) -> Chess960 {
Chess960 { game }
}
/// Returns a new instance of the variant from a FEN string
///
/// # Arguments
/// * `fen` - The FEN string that represents the game state
///
/// # Returns
/// A `Result<Chess960, FenError>` object
/// * `Ok(Chess960)` - A [Chess960] struct with the game state
/// * `Err(FenError)` - An error that indicates that the FEN string is invalid
///
/// # Example
/// ```
/// # use chess_lab::core::VariantBuilder;
/// # use chess_lab::variants::Chess960;
/// let fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
/// let variant = Chess960::from_fen(fen).unwrap();
/// ```
///
fn from_fen(fen: &str) -> Result<Chess960, FenError> {
Ok(Chess960 {
game: Game::from_fen(fen)?,
})
}
/// Returns a new instance of the variant from a PGN string
///
/// # Arguments
/// * `pgn` - The PGN string that represents the game state
///
/// # Returns
/// A `Result<Chess960, PgnError>` object
/// * `Ok(Chess960)` - A [Chess960] struct with the game state
/// * `Err(PgnError)` - An error that indicates that the PGN string is invalid
///
/// # Example
/// ```
/// # use chess_lab::core::VariantBuilder;
/// # use chess_lab::variants::Chess960;
/// let pgn = "[Variant \"Chess960\"]\n1. e4 e5 2. Nf3 Nc6";
/// let variant = Chess960::from_pgn(pgn).unwrap();
/// ```
///
fn from_pgn(pgn: &str) -> Result<Chess960, PGNError> {
parse_pgn(pgn)
}
/// Loads a new instance of the variant from a PGN file
///
/// # Arguments
/// * `path` - The path to the PGN file
///
/// # Returns
/// A `Result<Chess960, PgnError>` object
/// * `Ok(Chess960)` - A Chess960 struct with the game state
/// * `Err(PgnError)` - An error that indicates that the PGN file is invalid
///
/// # Example
/// ```
/// # use chess_lab::core::VariantBuilder;
/// # use chess_lab::variants::Chess960;
/// let path = "data/chess960/ex1.pgn";
/// let variant = Chess960::load(path).unwrap();
/// ```
///
fn load(path: &str) -> Result<Chess960, PGNError> {
let pgn = read_file(path)?;
Chess960::from_pgn(&pgn)
}
/// Loads all the instances of the variant from a PGN file
///
/// # Arguments
/// * `path` - The path to the PGN file
///
/// # Returns
/// A `Result<Vec<Chess960>, PgnError>` object
/// * `Ok(Vec<Chess960>)` - A vector with all the Chess960 structs with the game state
/// * `Err(PgnError)` - An error that indicates that the PGN file is invalid
///
/// # Example
/// ```
/// # use chess_lab::core::VariantBuilder;
/// # use chess_lab::variants::Chess960;
/// let path = "data/chess960/ex2.pgn";
/// let variants = Chess960::load_all(path).unwrap();
/// ```
///
fn load_all(path: &str) -> Result<Vec<Chess960>, PGNError> {
let pgn = read_file(path)?;
parse_multiple_pgn(&pgn)
}
}
impl Variant for Chess960 {
/// Moves a piece on the board
///
/// # Arguments
/// * `move_str` - The move string that represents the move to be made
///
/// # Returns
/// A `Result<GameStatus, MoveError>` object
/// * `Ok(GameStatus)` - The status of the game after the move
/// * `Err(MoveError)` - An error that indicates that the move is invalid
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let mut variant = Chess960::default();
/// variant.move_piece("e4").unwrap();
/// ```
///
fn move_piece(&mut self, move_str: &str) -> Result<GameStatus, MoveError> {
self.game.move_piece(move_str)
}
/// Undoes the last [Move] made
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let mut variant = Chess960::default();
/// variant.move_piece("e4").unwrap();
/// variant.undo();
/// ```
///
fn undo(&mut self) {
self.game.undo()
}
/// Redoes the last [Move] that was undone
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let mut variant = Chess960::default();
/// variant.move_piece("e4").unwrap();
/// variant.undo();
/// variant.redo();
/// ```
///
fn redo(&mut self) {
self.game.redo()
}
/// Returns the PGN string of the game
///
/// # Returns
/// A string with the PGN of the game
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let variant = Chess960::default();
/// let pgn = variant.pgn();
/// ```
///
fn pgn(&self) -> String {
self.game.pgn()
}
/// Returns the FEN string of the [Game]
///
/// # Returns
/// A string with the FEN of the [Game]
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
///
/// let variant = Chess960::default();
/// let fen = variant.fen();
/// ```
///
fn fen(&self) -> String {
self.game.fen()
}
/// Returns the piece at a given position
///
/// # Arguments
/// * `pos` - The position to get the piece from
///
/// # Returns
/// The piece at the given position, if there is one
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// use chess_lab::core::Position;
///
/// let variant = Chess960::default();
/// let piece = variant.get_piece_at(Position::from_string("e2").unwrap());
/// assert!(piece.is_some());
/// assert_eq!(piece.unwrap().to_string(), "P");
/// ```
///
fn get_piece_at(&self, pos: Position) -> Option<Piece> {
self.game.get_piece_at(pos)
}
/// Returns the legal moves of a piece at a given position
///
/// # Arguments
/// * `pos` - The position to get the legal moves from
///
/// # Returns
/// A vector with the legal moves of the piece at the given position
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// use chess_lab::core::Position;
///
/// let variant = Chess960::default();
/// let legal_moves = variant.get_legal_moves(Position::from_string("e2").unwrap());
/// assert!(legal_moves.iter().any(|m| m.to_string() == "e4"));
/// ```
///
fn get_legal_moves(&self, pos: Position) -> Vec<Move> {
self.game.get_legal_moves(pos)
}
/// Saves the PGN string of the [Game] to a file
///
/// # Arguments
/// * `path` - The path to the file
/// * `overwrite` - A boolean that indicates if the file should be overwritten
///
/// # Returns
/// A `Result<(), std::io::Error>` object
/// * `Ok(())` - The PGN was saved successfully
/// * `Err(std::io::Error)` - An error that indicates that the PGN could not be saved
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
///
/// let variant = Chess960::default();
/// variant.save("data/chess960/ex.pgn", true).unwrap();
/// # std::fs::remove_file("data/chess960/ex.pgn").unwrap();
/// ```
///
fn save(&self, path: &str, overwrite: bool) -> Result<(), std::io::Error> {
write_file(path, self.pgn().as_str(), !overwrite)?;
Ok(())
}
/// Resigns the [Game] for a [Color]
///
/// # Arguments
/// * `color` - The color that resigns
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// use chess_lab::core::Color;
///
/// let mut variant = Chess960::default();
/// variant.resign(Color::White);
/// ```
///
fn resign(&mut self, color: Color) {
self.game.resign(color)
}
/// Sets the [Game] as a draw
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let mut variant = Chess960::default();
/// variant.draw();
/// ```
///
fn draw(&mut self) {
self.game.draw_by_agreement()
}
/// Sets the game lost in time for a [Color]
///
/// # Arguments
/// * `color` - The [Color] that lost in time
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// use chess_lab::core::Color;
///
/// let mut variant = Chess960::default();
/// variant.lost_on_time(Color::White);
/// ```
///
fn lost_on_time(&mut self, color: Color) {
self.game.lost_on_time(color)
}
/// Returns the minified FEN string of the [Game]
///
/// # Returns
/// A string with the minified FEN of the [Game]
///
/// # Example
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let variant = Chess960::default();
/// let minified_fen = variant.get_minified_fen();
/// ```
///
fn get_minified_fen(&self) -> String {
get_minified_fen(&self.fen())
}
/// Returns the last [Move] of the [Game]
///
/// # Returns
/// The last [Move] of the [Game], if there is one
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::StandardChess;
/// let mut game = StandardChess::default();
/// game.move_piece("e4").unwrap();
/// let last_move = game.get_last_move();
/// assert_eq!(last_move.unwrap().to_string(), "e4");
/// ```
///
fn get_last_move(&self) -> Option<crate::core::Move> {
self.game.get_last_move()
}
/// Returns whether it is white's turn to move
///
/// # Returns
/// Whether it is white's turn to move
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let game = Chess960::default();
/// let color = game.is_white_turn();
/// ```
///
fn is_white_turn(&self) -> bool {
self.game.is_white_turn
}
/// Returns the halfmove clock of the [Game]
///
/// # Returns
/// The halfmove clock of the [Game]
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let game = Chess960::default();
/// let halfmove_clock = game.get_halfmove_clock();
/// ```
///
fn get_halfmove_clock(&self) -> u32 {
self.game.halfmove_clock
}
/// Returns the fullmove number of the [Game]
///
/// # Returns
/// The fullmove number of the [Game]
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let game = Chess960::default();
/// let fullmove_number = game.get_fullmove_number();
/// ```
///
fn get_fullmove_number(&self) -> u32 {
self.game.fullmove_number
}
/// Returns the current castling rights of the [Game]
///
/// # Returns
/// The current castling rights of the [Game]
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let game = Chess960::default();
/// let castling_rights = game.get_castling_rights();
/// ```
///
fn get_castling_rights(&self) -> String {
let mut castling_rights = String::new();
if self.game.castling_rights == 0 {
castling_rights.push('-');
} else {
if self.game.castling_rights & 0b1000 != 0 {
castling_rights.push('K');
}
if self.game.castling_rights & 0b0100 != 0 {
castling_rights.push('Q');
}
if self.game.castling_rights & 0b0010 != 0 {
castling_rights.push('k');
}
if self.game.castling_rights & 0b0001 != 0 {
castling_rights.push('q');
}
}
castling_rights
}
/// Returns the en passant square of the [Game]
///
/// # Returns
/// The en passant square of the [Game]
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let game = Chess960::default();
/// let en_passant = game.get_en_passant();
/// ```
///
fn get_en_passant(&self) -> Option<Position> {
self.game.en_passant
}
/// Returns the starting FEN of the [Game]
///
/// # Returns
/// A copy of the starting FEN of the [Game]
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
/// let game = Chess960::default();
/// let starting_fen = game.get_starting_fen();
/// ```
///
fn get_starting_fen(&self) -> String {
self.game.starting_fen.clone()
}
/// Returns the status of the [Game]
///
/// # Returns
/// The status of the [Game]
///
/// # Examples
/// ```
/// # use chess_lab::core::Variant;
/// # use chess_lab::variants::Chess960;
///
/// let game = Chess960::default();
/// let status = game.get_status();
/// ```
///
fn get_status(&self) -> GameStatus {
self.game.status
}
}
#[cfg(test)]
mod tests {
use crate::core::WinReason;
use super::*;
#[test]
fn test_standard_chess_name() {
assert_eq!(Chess960::name(), "Chess960");
}
#[test]
fn test_default() {
let variant = Chess960::default();
let minified_fen = variant.get_minified_fen();
let parts: Vec<&str> = minified_fen.split('/').collect();
assert!(parts[0].chars().all(|c| c.is_lowercase()));
assert!(parts[7].chars().all(|c| c.is_uppercase()));
assert_eq!(parts[0], parts[7].to_lowercase());
for piece in ['r', 'n', 'b', 'q', 'k'] {
let count = parts[0].chars().filter(|&c| c == piece).count();
match piece {
'r' => assert_eq!(count, 2),
'n' => assert_eq!(count, 2),
'b' => assert_eq!(count, 2),
'q' => assert_eq!(count, 1),
'k' => assert_eq!(count, 1),
_ => (),
}
}
let mut castle_chars = vec!['r', 'k', 'r'];
for char in parts[0].chars() {
if !castle_chars.is_empty() && char == castle_chars[0] {
castle_chars.remove(0);
}
}
assert!(castle_chars.is_empty());
}
#[test]
fn test_new() {
let game = Game::default();
let variant = Chess960::new(game.clone());
assert_eq!(variant.fen(), game.fen());
}
#[test]
fn test_from_fen() {
let fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
let variant = Chess960::from_fen(fen).unwrap();
assert_eq!(variant.fen(), fen);
}
#[test]
fn test_from_pgn() {
let pgn = "[Variant \"Chess960\"]\n
[FEN \"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1\"]\n
1. e4 e5 2. Nf3 Nc6 3. Bb5 a6";
let variant = Chess960::from_pgn(pgn).unwrap();
assert!(variant.pgn().contains("1. e4 e5 2. Nf3 Nc6 3. Bb5 a6"));
}
#[test]
fn test_load() {
let path = "data/chess960/ex1.pgn";
let variant = Chess960::load(path).unwrap();
assert!(variant.pgn().contains("1. e4 c6 2. d4 d5 3. exd5 cxd5"));
}
#[test]
fn test_load_all() {
let path = "data/chess960/ex2.pgn";
let variants = Chess960::load_all(path).unwrap();
assert_eq!(variants.len(), 3);
}
#[test]
fn test_move_piece() {
let mut variant =
Chess960::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
let status = variant.move_piece("e4").unwrap();
assert_eq!(status, GameStatus::InProgress);
assert_eq!(
variant.fen(),
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"
);
}
#[test]
fn test_get_piece_at() {
let variant =
Chess960::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
let piece = variant.get_piece_at(Position::from_string("e2").unwrap());
assert!(piece.is_some());
assert_eq!(piece.unwrap().to_string(), "P");
}
#[test]
fn test_get_legal_moves() {
let variant =
Chess960::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
let legal_moves = variant.get_legal_moves(Position::from_string("e2").unwrap());
assert!(legal_moves.iter().any(|m| m.to_string() == "e4"));
}
#[test]
fn test_undo_redo() {
let mut variant =
Chess960::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
variant.move_piece("e4").unwrap();
variant.undo();
assert_eq!(
variant.fen(),
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
);
variant.redo();
assert_eq!(
variant.fen(),
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1"
);
}
#[test]
fn test_save() {
let mut variant = Chess960::default();
let path = "data/chess960/test_save.pgn";
variant.move_piece("e4").unwrap();
variant.save(path, true).unwrap();
let loaded_variant = Chess960::load(path).unwrap();
assert_eq!(variant.fen(), loaded_variant.fen());
// Clean up
std::fs::remove_file(path).unwrap();
}
#[test]
fn test_resign() {
let mut variant = Chess960::default();
variant.resign(Color::White);
assert_eq!(
variant.get_status(),
GameStatus::BlackWins(WinReason::Resignation)
);
}
#[test]
fn test_draw() {
let mut variant = Chess960::default();
variant.draw();
assert_eq!(
variant.get_status(),
GameStatus::Draw(crate::core::DrawReason::Agreement)
);
}
#[test]
fn test_lost_on_time() {
let mut variant = Chess960::default();
variant.lost_on_time(Color::Black);
assert_eq!(variant.get_status(), GameStatus::WhiteWins(WinReason::Time));
}
#[test]
fn test_minified_fen() {
let variant =
Chess960::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1").unwrap();
let minified_fen = variant.get_minified_fen();
assert_eq!(minified_fen, "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR");
}
#[test]
fn test_get_last_move() {
let mut variant = Chess960::default();
assert_eq!(variant.get_last_move(), None);
variant.move_piece("e4").unwrap();
let last_move = variant.get_last_move();
assert!(last_move.is_some());
assert_eq!(last_move.unwrap().to_string(), "e4");
}
#[test]
fn test_is_white_turn() {
let mut variant = Chess960::default();
assert!(variant.is_white_turn());
variant.move_piece("e4").unwrap();
assert!(!variant.is_white_turn());
}
#[test]
fn test_get_castling_rights() {
let mut variant = Chess960::default();
let castling_rights = variant.get_castling_rights();
assert_eq!(castling_rights, "KQkq");
variant =
Chess960::from_fen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1").unwrap();
let castling_rights = variant.get_castling_rights();
assert_eq!(castling_rights, "-");
}
#[test]
fn test_get_en_passant() {
let mut variant = Chess960::default();
assert_eq!(variant.get_en_passant(), None);
variant.move_piece("e4").unwrap();
variant.move_piece("d5").unwrap();
variant.move_piece("e5").unwrap();
variant.move_piece("f5").unwrap();
assert_eq!(
variant.get_en_passant().unwrap(),
Position::new(5, 5).unwrap()
);
}
#[test]
fn test_get_halfmove_clock() {
let variant = Chess960::default();
assert_eq!(variant.get_halfmove_clock(), 0);
}
#[test]
fn test_get_fullmove_number() {
let variant = Chess960::default();
assert_eq!(variant.get_fullmove_number(), 1);
}
#[test]
fn test_get_starting_fen() {
let variant = Chess960::default();
let starting_fen = variant.get_starting_fen();
assert!(starting_fen.contains("w KQkq - 0 1"));
}
#[test]
fn test_get_status() {
let variant = Chess960::default();
assert_eq!(variant.get_status(), GameStatus::InProgress);
}
}