BitBully 0.0.39
Loading...
Searching...
No Matches
MoveSorter.hpp
1/*
2 * This file is part of Connect4 Game Solver <http://connect4.gamesolver.org>
3 * Copyright (C) 2017-2019 Pascal Pons <contact@gamesolver.org>
4 *
5 * Connect4 Game Solver is free software: you can redistribute it and/or
6 * modify it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Connect4 Game Solver is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Connect4 Game Solver. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef MOVE_SORTER_HPP
20#define MOVE_SORTER_HPP
21
22#include "Position.hpp"
23
24namespace GameSolver {
25namespace Connect4 {
26
39 public:
40
45 void add(const Position::position_t move, const int score) {
46 int pos = size++;
47 for(; pos && entries[pos - 1].score > score; --pos) entries[pos] = entries[pos - 1];
48 entries[pos].move = move;
49 entries[pos].score = score;
50 }
51
57 Position::position_t getNext() {
58 if(size)
59 return entries[--size].move;
60 else
61 return 0;
62 }
63
67 void reset() {
68 size = 0;
69 }
70
74 MoveSorter(): size{0} {
75 }
76
77 private:
78 // number of stored moves
79 unsigned int size;
80
81 // Contains size moves with their score ordered by score
82 struct {
83 Position::position_t move;
84 int score;
85 } entries[Position::WIDTH];
86};
87
88} // namespace Connect4
89} // namespace GameSolver
90#endif
void add(const Position::position_t move, const int score)
Position::position_t getNext()