Skip to content

Commit 7fe5729

Browse files
author
Jesper Torp Kristensen
committed
Removed use of global variable
1 parent 0677d2e commit 7fe5729

File tree

11 files changed

+105
-217
lines changed

11 files changed

+105
-217
lines changed

src/board_2.cxx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -738,26 +738,22 @@ bool Board2::clr_board2(Board *board, ostream& os, vector<string> &p) {
738738
} else if (dot_demand(p, 3, "print", "move", "list")) {
739739
b.print_moves(cerr);
740740
} else if (dot_demand(p, 4, "print", "move", "list", (uintptr_t)1)) {
741-
b.print_moves(cerr, ILLEGAL_POS, ILLEGAL_POS,
742-
PIECE_KIND[char_to_piece(parse_result[0][0])]);
741+
b.print_moves(cerr, ILLEGAL_POS, ILLEGAL_POS, PIECE_KIND[char_to_piece(p[3][0])]);
743742

744743
} else if (dot_demand(p, 4, "print", "moves", "to", (uintptr_t)2)) {
745-
b.print_moves(cerr, ILLEGAL_POS, strToPos(parse_result[0]));
744+
b.print_moves(cerr, ILLEGAL_POS, strToPos(p[3]));
746745
} else if (dot_demand(p, 5, "print", "moves", "to", (uintptr_t)2, (uintptr_t)1)) {
747-
b.print_moves(cerr, ILLEGAL_POS, strToPos(parse_result[1]),
748-
PIECE_KIND[char_to_piece(parse_result[1][0])]);
746+
b.print_moves(cerr, ILLEGAL_POS, strToPos(p[3]), PIECE_KIND[char_to_piece(p[4][0])]);
749747

750748
} else if (dot_demand(p, 4, "print", "moves", "from", (uintptr_t)2)) {
751-
b.print_moves(cerr, strToPos(parse_result[0]));
749+
b.print_moves(cerr, strToPos(p[3]));
752750
} else if (dot_demand(p, 5, "print", "moves", "from", (uintptr_t)2, (uintptr_t)1)) {
753-
b.print_moves(cerr, strToPos(parse_result[0]), ILLEGAL_POS,
754-
PIECE_KIND[char_to_piece(parse_result[1][0])]);
751+
b.print_moves(cerr, strToPos(p[3]), ILLEGAL_POS, PIECE_KIND[char_to_piece(p[4][0])]);
755752

756753
} else if (dot_demand(p, 6, "print", "moves", "from", "to", (uintptr_t)2, (uintptr_t)2)) {
757-
b.print_moves(cerr, strToPos(parse_result[0]), strToPos(parse_result[1]));
754+
b.print_moves(cerr, strToPos(p[4]), strToPos(p[5]));
758755
} else if (dot_demand(p, 7, "print", "moves", "from", "to", (uintptr_t)2, (uintptr_t)2, (uintptr_t)1)) {
759-
b.print_moves(cerr, strToPos(parse_result[0]), strToPos(parse_result[1]),
760-
PIECE_KIND[char_to_piece(parse_result[2][0])]);
756+
b.print_moves(cerr, strToPos(p[4]), strToPos(p[5]), PIECE_KIND[char_to_piece(p[6][0])]);
761757

762758
} else if (dot_demand(p, 3, "print", "bit", "boards")) {
763759
b.print_bit_boards(cerr);
@@ -777,16 +773,16 @@ bool Board2::clr_board2(Board *board, ostream& os, vector<string> &p) {
777773

778774
} else if (dot_demand(p, 3, "retro", "moves", (uintptr_t)2)) {
779775
vector<triple<Move,Undo,int> > rm = b.get_retro_moves(true, true, true, true);
780-
os << "List of retro move(s) from current position with destination " << parse_result[0] << "\n";
776+
os << "List of retro move(s) from current position with destination " << p[2] << "\n";
781777
for (uint i=0; i<rm.size(); i++) {
782-
if (POS_NAME[rm[i].first.to] == parse_result[0])
778+
if (POS_NAME[rm[i].first.to] == p[2])
783779
os << i << ":\t" << rm[i].first.toString2() << "\t"
784780
<< rm[i].third << "\t" << rm[i].second.toString() << "\n";
785781
}
786782

787783
} else if (dot_demand(p, 3, "retro", "move", (uintptr_t)0)) {
788784
vector<triple<Move,Undo,int> > rm = b.get_retro_moves(true, true, true, true);
789-
uint n = atoi(parse_result[0].c_str());
785+
uint n = atoi(p[2].c_str());
790786
if (0<=n && n<rm.size()) {
791787
os << "Undoing retro move number " << n;
792788
if (rm[n].third) {
@@ -1316,7 +1312,7 @@ bool Board2::find_legal_move(Move& move) {
13161312

13171313

13181314
// triple<check_count, prev_num_checks, threat_pos>
1319-
// Assume it is white-to-move and we wish to the possible last moves for black.
1315+
// Assume it is white-to-move and we wish to get the possible last moves for black.
13201316
// check_count is the number of checks against whites king. After taking back one of
13211317
// blacks moves it should be 0 - otherwise black could instead have captured whites king
13221318
// - hence the position would be illegal.
@@ -1373,7 +1369,7 @@ triple<int,uint8_t,Position> Board2::retro_move_count_checks(Position from, Posi
13731369

13741370
check_count -= checktable(pattern, player);
13751371

1376-
// Just or the 11 pattern of a blocking piece on top of board[to]
1372+
// Just or the 11b pattern of a blocking piece on top of board[to]
13771373
int line_index = d_to ? (to>>3) : (to&7);
13781374
pattern |= DIAG_PATTERN[line_index][ 3 ];
13791375

@@ -1615,7 +1611,7 @@ triple<int,uint8_t,Position> Board2::retro_move_count_checks(Position from, Posi
16151611
struct EnPassantPP {
16161612
EnPassantPP() : ep(ILLEGAL_POS), ep_pawn(0) {}
16171613

1618-
// For the en passant at ep to be valid, the positions p1 and p2 may not be occupied
1614+
// For the en passant at ep to be valid, the positions p1 and p2 must not be occupied
16191615
EnPassantPP(Position p1, Position p2, Position ep) : ep(ep), ep_pawn(0) {
16201616
assert(p1<=ILLEGAL_POS && p2<=ILLEGAL_POS && ep<=ILLEGAL_POS);
16211617
illegal_from.set(p1);

src/board_2.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected:
138138

139139

140140
// position_is_unreachable is set by set_check_invariants().
141-
// Hence it will abso be set by loadFEN and set_board.
141+
// Hence it will be set by loadFEN and set_board.
142142
char position_is_unreachable;
143143

144144

@@ -163,7 +163,7 @@ protected:
163163

164164
// Is own king checked if placed on pos!=its current position (illegal move).
165165
// If pos is a position that the king can move to, then it
166-
// is not nescessary to remove the king from its current position.
166+
// is not necessary to remove the king from its current position.
167167
// If a piece is placed on pos, it is assumed this is captured.
168168
bool check_if_king_placed(Position pos) const;
169169

src/board_2_plus.cxx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -882,23 +882,23 @@ bool Board2plus::clr_board2plus(Board *board, ostream &os, vector<string> &p) {
882882
b.see.test_see_list();
883883

884884
} else if (dot_demand(p, 4, "see", (uintptr_t)1, (uintptr_t)6, (uintptr_t)6)) {
885-
Piece victim = PIECE_KIND[char_to_piece(parse_result[0][0])];
885+
Piece victim = PIECE_KIND[char_to_piece(p[1][0])];
886886
if (victim) {
887887
uint16_t a = 0;
888-
a += (parse_result[1][5]-'0');
889-
a += (parse_result[1][4]-'0') << 2;
890-
a += (parse_result[1][3]-'0') << 5;
891-
a += (parse_result[1][2]-'0') << 8;
892-
a += (parse_result[1][1]-'0') << 11;
893-
a += (parse_result[1][0]-'0') << 15;
888+
a += (p[2][5]-'0');
889+
a += (p[2][4]-'0') << 2;
890+
a += (p[2][3]-'0') << 5;
891+
a += (p[2][2]-'0') << 8;
892+
a += (p[2][1]-'0') << 11;
893+
a += (p[2][0]-'0') << 15;
894894
cerr << "Aggressor = " << b.see.capture_list_to_string(a) << "\n";
895895
uint16_t d = 0;
896-
d += (parse_result[2][5]-'0');
897-
d += (parse_result[2][4]-'0') << 2;
898-
d += (parse_result[2][3]-'0') << 5;
899-
d += (parse_result[2][2]-'0') << 8;
900-
d += (parse_result[2][1]-'0') << 11;
901-
d += (parse_result[2][0]-'0') << 15;
896+
d += (p[3][5]-'0');
897+
d += (p[3][4]-'0') << 2;
898+
d += (p[3][3]-'0') << 5;
899+
d += (p[3][2]-'0') << 8;
900+
d += (p[3][1]-'0') << 11;
901+
d += (p[3][0]-'0') << 15;
902902
cerr << "Defender = " << b.see.capture_list_to_string(d) << "\n";
903903

904904
int result = b.see.calc_see(victim, a, d);
@@ -908,9 +908,9 @@ bool Board2plus::clr_board2plus(Board *board, ostream &os, vector<string> &p) {
908908
}
909909

910910
} else if (dot_demand(p, 4, "see2", (uintptr_t)1, (uintptr_t)3, (uintptr_t)3)) {
911-
Piece victim = char_to_piece(parse_result[0][0]);
912-
int a = 100*(parse_result[1][0]-'0') + 10*(parse_result[1][1]-'0') + (parse_result[1][2]-'0');
913-
int d = 100*(parse_result[2][0]-'0') + 10*(parse_result[2][1]-'0') + (parse_result[2][2]-'0');
911+
Piece victim = char_to_piece(p[1][0]);
912+
int a = 100*(p[2][0]-'0') + 10*(p[2][1]-'0') + (p[2][2]-'0');
913+
int d = 100*(p[3][0]-'0') + 10*(p[3][1]-'0') + (p[3][2]-'0');
914914

915915
int result = b.see.index_see(victim, a, d);
916916
cerr << "Result of battle = " << result << " units (a pawn is 8 units).\n";

src/chess.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void receive_messages() {
310310

311311
int max_moves = 999999;
312312
if (dot_demand(p, 3, "load", (uintptr_t)0, (uintptr_t)0))
313-
sscanf(parse_result[1].c_str(), "%d", &max_moves);
313+
sscanf(p[2].c_str(), "%d", &max_moves);
314314

315315
pgn_loader.print_tags(cerr);
316316

@@ -517,7 +517,7 @@ void receive_messages() {
517517

518518
} else if (dot_demand(p, 2, "undo", (uintptr_t)0)) {
519519
comm->cpu_color = NEITHER_COLOR;
520-
int i = atoi(parse_result[0].c_str());
520+
int i = atoi(p[1].c_str());
521521
while (--i >= 0 && cpu->undo_move());
522522
cpu->print_board(cerr, -2);
523523

@@ -661,15 +661,15 @@ bool debug_message(string message) {
661661
srand(seed);
662662

663663
} else if (dot_demand(p, 2, "randseed", (uintptr_t)0)) {
664-
int seed = atoi(parse_result[0].c_str());
664+
int seed = atoi(p[1].c_str());
665665
cerr << "Calling srand(" << seed << ")\n";
666666
srand(seed);
667667

668668
} else if (dot_demand(p, 1, "dir")) {
669669
cpu->print_board(cerr, -2);
670670

671671
} else if (dot_demand(p, 2, "dir", (uintptr_t)0)) {
672-
int from_move = atoi(parse_result[0].c_str());
672+
int from_move = atoi(p[1].c_str());
673673
cpu->print_board(cerr, from_move);
674674

675675
} else if (dot_demand(p, 1, "redo")) {
@@ -680,15 +680,15 @@ bool debug_message(string message) {
680680
}
681681

682682
} else if (dot_demand(p, 2, "redo", (uintptr_t)0)) {
683-
int i = atoi(parse_result[0].c_str());
683+
int i = atoi(p[1].c_str());
684684
while (--i >= 0 && cpu->try_redo_move()) ;
685685
cpu->print_board(cerr, -2);
686686

687687
} else if (dot_demand(p, 1, "pml")) {
688688
cpu->print_moves(cerr);
689689

690690
} else if (dot_demand(p, 3, "search", "version", (uintptr_t)1)) {
691-
int s = parse_result[0][0] - '0';
691+
int s = p[2][0] - '0';
692692
if (1<=s && s<=NUM_SEARCH_VERSIONS) {
693693
search_version = s;
694694
if (clr) {
@@ -699,11 +699,11 @@ bool debug_message(string message) {
699699
}
700700

701701
} else if (dot_demand(p, 3, "tree", "size", (uintptr_t)0)) {
702-
int n = atoi(parse_result[0].c_str());
702+
int n = atoi(p[2].c_str());
703703
show_minimal_alpha_beta_tree_sizes(cerr, n, 12);
704704

705705
} else if (dot_demand(p, 3, "evaluation", "version", (uintptr_t)1)) {
706-
int e = parse_result[0][0] - '0';
706+
int e = p[2][0] - '0';
707707
if (1<=e && e<=NUM_EVAL_VERSIONS) {
708708
evaluation_version = e;
709709
if (clr) {
@@ -724,7 +724,7 @@ bool debug_message(string message) {
724724
comm->settings.print(cerr);
725725

726726
} else if (dot_demand(p, 3, "set", (uintptr_t)0, (uintptr_t)0)) {
727-
comm->settings.define(parse_result[0], parse_result[1]);
727+
comm->settings.define(p[1], p[2]);
728728

729729
} else if (dot_demand(p, 3, "test", "opening", "library")) {
730730
Move move = cpu->moves();

0 commit comments

Comments
 (0)