mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00:00
Retire Application class
It is a redundant boiler plate, just call initialization and resource release directly from main() No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
00d9fe8af0
commit
efeb37c33f
12 changed files with 30 additions and 124 deletions
|
@ -33,7 +33,7 @@ BINDIR = $(PREFIX)/bin
|
||||||
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
PGOBENCH = ./$(EXE) bench 32 1 10 default depth
|
||||||
|
|
||||||
### Object files
|
### Object files
|
||||||
OBJS = application.o bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
OBJS = bitboard.o pawns.o material.o endgame.o evaluate.o main.o \
|
||||||
misc.o move.o movegen.o history.o movepick.o search.o position.o \
|
misc.o move.o movegen.o history.o movepick.o search.o position.o \
|
||||||
direction.o tt.o uci.o ucioption.o book.o bitbase.o san.o benchmark.o timeman.o
|
direction.o tt.o uci.o ucioption.o book.o bitbase.o san.o benchmark.o timeman.o
|
||||||
|
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
////
|
|
||||||
//// Includes
|
|
||||||
////
|
|
||||||
|
|
||||||
#include "bitboard.h"
|
|
||||||
#include "direction.h"
|
|
||||||
#include "endgame.h"
|
|
||||||
#include "evaluate.h"
|
|
||||||
#include "material.h"
|
|
||||||
#include "misc.h"
|
|
||||||
#include "movepick.h"
|
|
||||||
#include "position.h"
|
|
||||||
#include "search.h"
|
|
||||||
#include "thread.h"
|
|
||||||
#include "ucioption.h"
|
|
||||||
|
|
||||||
|
|
||||||
/// Application class is in charge of initializing global resources
|
|
||||||
/// at startup and cleanly releases them when program terminates.
|
|
||||||
|
|
||||||
Application::Application() {
|
|
||||||
|
|
||||||
init_direction_table();
|
|
||||||
init_bitboards();
|
|
||||||
init_uci_options();
|
|
||||||
Position::init_zobrist();
|
|
||||||
Position::init_piece_square_tables();
|
|
||||||
init_eval(1);
|
|
||||||
init_bitbases();
|
|
||||||
init_search();
|
|
||||||
init_threads();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::initialize() {
|
|
||||||
|
|
||||||
// A static Application object is allocated
|
|
||||||
// once only when this function is called.
|
|
||||||
static Application singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::free_resources() {
|
|
||||||
|
|
||||||
// Warning, following functions reference global objects that
|
|
||||||
// must be still alive when free_resources() is called.
|
|
||||||
exit_threads();
|
|
||||||
quit_eval();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::exit_with_failure() {
|
|
||||||
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
|
||||||
Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
|
|
||||||
Copyright (C) 2008-2010 Marco Costalba, Joona Kiiski, Tord Romstad
|
|
||||||
|
|
||||||
Stockfish is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Stockfish is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#if !defined(APPLICATION_H_INCLUDED)
|
|
||||||
#define APPLICATION_H_INCLUDED
|
|
||||||
|
|
||||||
|
|
||||||
/// Singleton class used to housekeep memory and global resources
|
|
||||||
/// so to be sure we always leave in a clean state.
|
|
||||||
|
|
||||||
class Application {
|
|
||||||
|
|
||||||
Application();
|
|
||||||
Application(const Application&);
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void initialize();
|
|
||||||
static void free_resources();
|
|
||||||
static void exit_with_failure();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // !defined(APPLICATION_H_INCLUDED)
|
|
|
@ -102,7 +102,7 @@ void benchmark(int argc, char* argv[]) {
|
||||||
if (!fenFile.is_open())
|
if (!fenFile.is_open())
|
||||||
{
|
{
|
||||||
cerr << "Unable to open positions file " << posFile << endl;
|
cerr << "Unable to open positions file " << posFile << endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
string pos;
|
string pos;
|
||||||
while (fenFile.good())
|
while (fenFile.good())
|
||||||
|
|
|
@ -376,7 +376,7 @@ void Book::open(const string& fName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cerr << "Failed to open book file " << fileName << endl;
|
cerr << "Failed to open book file " << fileName << endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -496,7 +496,7 @@ void Book::read_entry(BookEntry& entry, int idx) {
|
||||||
if (!good())
|
if (!good())
|
||||||
{
|
{
|
||||||
cerr << "Failed to read book entry at index " << idx << endl;
|
cerr << "Failed to read book entry at index " << idx << endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/main.cpp
24
src/main.cpp
|
@ -28,8 +28,17 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "bitboard.h"
|
||||||
#include "bitcount.h"
|
#include "bitcount.h"
|
||||||
|
#include "direction.h"
|
||||||
|
#include "endgame.h"
|
||||||
|
#include "evaluate.h"
|
||||||
|
#include "material.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "position.h"
|
||||||
|
#include "search.h"
|
||||||
|
#include "thread.h"
|
||||||
|
#include "ucioption.h"
|
||||||
|
|
||||||
#ifdef USE_CALLGRIND
|
#ifdef USE_CALLGRIND
|
||||||
#include <valgrind/callgrind.h>
|
#include <valgrind/callgrind.h>
|
||||||
|
@ -50,8 +59,16 @@ int main(int argc, char* argv[]) {
|
||||||
cout.rdbuf()->pubsetbuf(NULL, 0);
|
cout.rdbuf()->pubsetbuf(NULL, 0);
|
||||||
cin.rdbuf()->pubsetbuf(NULL, 0);
|
cin.rdbuf()->pubsetbuf(NULL, 0);
|
||||||
|
|
||||||
// Initialization through global resources manager
|
// Startup initializations
|
||||||
Application::initialize();
|
init_direction_table();
|
||||||
|
init_bitboards();
|
||||||
|
init_uci_options();
|
||||||
|
Position::init_zobrist();
|
||||||
|
Position::init_piece_square_tables();
|
||||||
|
init_eval(1);
|
||||||
|
init_bitbases();
|
||||||
|
init_search();
|
||||||
|
init_threads();
|
||||||
|
|
||||||
#ifdef USE_CALLGRIND
|
#ifdef USE_CALLGRIND
|
||||||
CALLGRIND_START_INSTRUMENTATION;
|
CALLGRIND_START_INSTRUMENTATION;
|
||||||
|
@ -79,6 +96,7 @@ int main(int argc, char* argv[]) {
|
||||||
benchmark(argc, argv);
|
benchmark(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::free_resources();
|
exit_threads();
|
||||||
|
quit_eval();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ MaterialInfoTable::MaterialInfoTable() {
|
||||||
{
|
{
|
||||||
cerr << "Failed to allocate " << MaterialTableSize * sizeof(MaterialInfo)
|
cerr << "Failed to allocate " << MaterialTableSize * sizeof(MaterialInfo)
|
||||||
<< " bytes for material hash table." << endl;
|
<< " bytes for material hash table." << endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo));
|
memset(entries, 0, MaterialTableSize * sizeof(MaterialInfo));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "application.h"
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
|
@ -91,7 +91,7 @@ PawnInfoTable::PawnInfoTable() {
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << (PawnTableSize * sizeof(PawnInfo))
|
std::cerr << "Failed to allocate " << (PawnTableSize * sizeof(PawnInfo))
|
||||||
<< " bytes for pawn hash table." << std::endl;
|
<< " bytes for pawn hash table." << std::endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
memset(entries, 0, PawnTableSize * sizeof(PawnInfo));
|
memset(entries, 0, PawnTableSize * sizeof(PawnInfo));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2324,7 +2324,7 @@ split_point_start: // At split points actual search starts from here
|
||||||
if (!ok)
|
if (!ok)
|
||||||
{
|
{
|
||||||
cout << "Failed to create thread number " << i << endl;
|
cout << "Failed to create thread number " << i << endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait until the thread has finished launching and is gone to sleep
|
// Wait until the thread has finished launching and is gone to sleep
|
||||||
|
|
|
@ -70,7 +70,7 @@ void TranspositionTable::set_size(size_t mbSize) {
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to allocate " << mbSize
|
std::cerr << "Failed to allocate " << mbSize
|
||||||
<< " MB for transposition table." << std::endl;
|
<< " MB for transposition table." << std::endl;
|
||||||
Application::exit_with_failure();
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#if !defined(TYPES_H_INCLUDED)
|
#if !defined(TYPES_H_INCLUDED)
|
||||||
#define TYPES_H_INCLUDED
|
#define TYPES_H_INCLUDED
|
||||||
|
|
||||||
|
@ -51,6 +50,7 @@ typedef uint64_t Key;
|
||||||
// Bitboard type
|
// Bitboard type
|
||||||
typedef uint64_t Bitboard;
|
typedef uint64_t Bitboard;
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
////
|
////
|
||||||
//// Configuration
|
//// Configuration
|
||||||
|
|
Loading…
Add table
Reference in a new issue