├── .gitignore
├── README.md
├── chenard.sln
├── chenard.vcproj
├── chenard_screen_shot.png
├── chenclient
├── build
├── chenclient.vcxproj
├── chenclient.vcxproj.filters
└── main.cpp
├── chenserver
├── build
├── chenserver.cpp
├── chenserver.h
├── chenserver.vcxproj
├── chenserver.vcxproj.filters
├── gamestate.cpp
├── ifstdio.cpp
├── iftcp.cpp
├── linux-source-files
├── uiserver.cpp
└── uiserver.h
├── fen
├── .idea
│ ├── jsLibraryMappings.xml
│ └── typescript-compiler.xml
├── bitmap
│ ├── bbb.png
│ ├── bbk.png
│ ├── bbn.png
│ ├── bbp.png
│ ├── bbq.png
│ ├── bbr.png
│ ├── bsq.png
│ ├── bwb.png
│ ├── bwk.png
│ ├── bwn.png
│ ├── bwp.png
│ ├── bwq.png
│ ├── bwr.png
│ ├── wbb.png
│ ├── wbk.png
│ ├── wbn.png
│ ├── wbp.png
│ ├── wbq.png
│ ├── wbr.png
│ ├── wsq.png
│ ├── wwb.png
│ ├── wwk.png
│ ├── wwn.png
│ ├── wwp.png
│ ├── wwq.png
│ └── wwr.png
├── fen.ts
├── fentool.css
├── index.html
├── jquery.d.ts
├── tsconfig.json
└── ui.ts
├── images
├── README.md
├── bb.bmp
├── bb.png
├── bb.svg
├── bk.bmp
├── bk.png
├── bk.svg
├── bn.bmp
├── bn.png
├── bn.svg
├── bp.bmp
├── bp.png
├── bp.svg
├── bq.bmp
├── bq.png
├── bq.svg
├── br.bmp
├── br.png
├── br.svg
├── makepng
├── wb.bmp
├── wb.png
├── wb.svg
├── wk.bmp
├── wk.png
├── wk.svg
├── wn.bmp
├── wn.png
├── wn.svg
├── wp.bmp
├── wp.png
├── wp.svg
├── wq.bmp
├── wq.png
├── wq.svg
├── wr.bmp
├── wr.png
└── wr.svg
├── linux
├── build
├── run
├── sourcefiles
├── vgbuild
├── vgtest
├── xbuild
└── xsourcefiles
├── openbook
├── chenard.obt
├── contain.h
├── ddc.h
├── limp.cpp
├── obt.bat
├── obt.cpp
├── openbook.cpp
├── openbook.vcproj
├── openbook.vcxproj
└── openbook.vcxproj.filters
├── portable
├── portable.vcproj
├── portable.vcxproj
└── portable.vcxproj.filters
├── res
├── chenard1.ico
├── resource.h
└── winchen.rc
├── src
├── attack.cpp
├── board.cpp
├── canmove.cpp
├── chenga.cpp
├── chenga.h
├── chengene.cpp
├── chess.h
├── clntree.cpp
├── convert.cpp
├── crand.cpp
├── dispgame.cpp
├── dumptree.cpp
├── edittree.cpp
├── egdbase.cpp
├── endgame.cpp
├── eval.cpp
├── fancy.cpp
├── fixtree.cpp
├── game.cpp
├── gamefile.cpp
├── gamefile.h
├── gencaps.cpp
├── genmove.cpp
├── human.cpp
├── ichess.cpp
├── ichess.h
├── kbd.h
├── learn.cpp
├── lichess.cpp
├── lichess.h
├── linuxtime.cpp
├── lrntree.cpp
├── lrntree.h
├── material.cpp
├── misc.cpp
├── morder.cpp
├── move.cpp
├── npchess.cpp
├── npchess.h
├── obsolete
│ ├── msdos
│ │ ├── doscga.cpp
│ │ ├── dostime.cpp
│ │ ├── dosvga.cpp
│ │ ├── mailches.cpp
│ │ ├── uicga.cpp
│ │ ├── uicga.h
│ │ ├── uivga.cpp
│ │ └── uivga.h
│ └── os2
│ │ └── brdbuf.cpp
├── openbook.cpp
├── opening.cpp
├── player.cpp
├── portable.cpp
├── profiler.cpp
├── profiler.h
├── search.cpp
├── speak.cpp
├── stdtime.cpp
├── taggit
├── textundo.cpp
├── transpos.cpp
├── ui.cpp
├── uistdio.cpp
├── uistdio.h
├── uiwin32.cpp
├── uixboard.cpp
├── uixboard.h
├── undopath.cpp
├── unmove.cpp
├── wbrdbuf.cpp
├── winchess.h
├── wingui.cpp
├── winguich.h
├── wintime.cpp
└── xchenard.cpp
├── ttychess
├── ttychess.sln
└── ttychess
│ ├── ttychess.cpp
│ ├── ttychess.ini
│ ├── ttychess.vcxproj
│ └── ttychess.vcxproj.filters
├── winbin
└── rebuild.bat
├── winchen
├── winchen.vcproj
├── winchen.vcxproj
└── winchen.vcxproj.filters
└── xchenard
├── xchenard.vcproj
├── xchenard.vcxproj
└── xchenard.vcxproj.filters
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | logs/
3 | bin
4 | obj
5 | Debug
6 | Release
7 | *.db
8 | *.opendb
9 | *.sdf
10 | *.opensdf
11 | *.suo
12 | *.user
13 | *.userprefs
14 | *.resources
15 | *.swp
16 | *.pyc
17 | *.psess
18 | *.vsp
19 | .idea
20 | *.map
21 | *.aps
22 | *.trx
23 | fen/fen.js
24 | fen/ui.js
25 | src/tags
26 | chenclient/chenclient
27 | chenserver/chenserver
28 | linux/chenard
29 | linux/vgchenard
30 | linux/xchenard
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Chenard - an open source chess program
2 |
3 |
4 |
5 | Chenard is a free and open source chess program written in C++.
6 | The code is very mature and well-tested (started in 1993).
7 | It is not the strongest AI out there, but it will provide a serious challenge for most people.
8 |
9 | Chenard supports the following platforms:
10 |
11 | - Windows 32-bit and 64-bit (GUI and command-line).
12 | - [ChenServer](https://github.com/cosinekitty/chenard/wiki/ChenServer) TCP server (provides chess logic outside of C/C++).
13 | - WinBoard plug-in engine.
14 | - Linux xboard plug-in engine.
15 | - Linux command-line.
16 | - Mac OS command-line.
17 | - TTY version for use on serial teletype machines.
18 |
19 | For more information, see the [Chenard home page](http://cosinekitty.com/chenard/).
20 |
--------------------------------------------------------------------------------
/chenard_screen_shot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/chenard_screen_shot.png
--------------------------------------------------------------------------------
/chenclient/build:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | g++ -o chenclient -std=c++0x -Wall -Werror -Wextra -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual -O2 -I ../src main.cpp
3 |
--------------------------------------------------------------------------------
/chenclient/chenclient.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/chenclient/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | main.cpp - Sample client for ChenServer, by Don Cross.
3 |
4 | https://github.com/cosinekitty/chenard/wiki/ChenServer
5 | */
6 |
7 | #if defined(__linux__) || defined(__APPLE__)
8 | # define CHENARD_LINUX 1
9 | #else
10 | # define CHENARD_LINUX 0
11 | #endif
12 |
13 | #include
14 | #include
15 | #include
16 | #if CHENARD_LINUX
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | // Hacks to help WinSock code build on Linux.
27 | typedef int SOCKET;
28 | typedef sockaddr_in SOCKADDR_IN;
29 | typedef sockaddr *LPSOCKADDR;
30 | const int INVALID_SOCKET = -1;
31 |
32 | inline bool IsValidSocket(SOCKET s)
33 | {
34 | return s >= 0;
35 | }
36 |
37 | inline int closesocket(SOCKET s)
38 | {
39 | return close(s);
40 | }
41 | #else
42 | #ifdef _MSC_VER // Windows?
43 | #define _WINSOCK_DEPRECATED_NO_WARNINGS
44 | #include
45 | #include
46 |
47 | inline bool IsValidSocket(SOCKET s)
48 | {
49 | return s != INVALID_SOCKET;
50 | }
51 | #else
52 | #error We do not know how to do socket programming on this platform.
53 | #endif
54 | #endif
55 |
56 | bool SendCommand(const std::string& server, int port, const std::string& command, std::string& response);
57 |
58 | int main(int argc, const char *argv[])
59 | {
60 | if (argc != 4)
61 | {
62 | std::cerr << "USAGE: chenclient server port \"message\"" << std::endl;
63 | std::cerr << std::endl;
64 | std::cerr << "For more information, visit:" << std::endl;
65 | std::cerr << "https://github.com/cosinekitty/chenard/wiki/ChenServer" << std::endl;
66 | return 1;
67 | }
68 |
69 | const char *server = argv[1];
70 | int port = atoi(argv[2]);
71 | const char *message = argv[3];
72 |
73 | if (port <= 0 || port > 0xffff)
74 | {
75 | std::cerr << "ERROR: Invalid port number '" << argv[2] << "'" << std::endl;
76 | return 1;
77 | }
78 |
79 | #ifdef _MSC_VER
80 | WSADATA data;
81 | const WORD versionRequested = MAKEWORD(2, 2);
82 | int result = WSAStartup(versionRequested, &data);
83 | if (result == 0)
84 | {
85 | if (data.wVersion == versionRequested)
86 | {
87 | #endif
88 | std::string response;
89 | if (SendCommand(server, port, message, response))
90 | {
91 | std::cout << response << std::endl;
92 | }
93 | #ifdef _MSC_VER
94 | }
95 | else
96 | {
97 | std::cerr << "ERROR: Wrong version of WinSock." << std::endl;
98 | }
99 | WSACleanup();
100 | }
101 | else
102 | {
103 | std::cerr << "ERROR: Could not initialize WinSock." << std::endl;
104 | }
105 | #endif
106 | return 1;
107 | }
108 |
109 |
110 | bool SendCommand(const std::string& server, int port, const std::string& command, std::string& response)
111 | {
112 | bool success = false;
113 | response.clear();
114 |
115 | hostent *host = gethostbyname(server.c_str());
116 | if (host == nullptr)
117 | {
118 | std::cerr << "ERROR: Cannot resolve host '" << server << "'" << std::endl;
119 | }
120 | else
121 | {
122 | const std::string iptext = inet_ntoa(**(in_addr **)host->h_addr_list);
123 | //std::cout << "Resolved host '" << host->h_name << "' = " << iptext << std::endl;
124 | SOCKADDR_IN target;
125 | target.sin_family = AF_INET;
126 | target.sin_port = htons(port);
127 | target.sin_addr.s_addr = inet_addr(iptext.c_str());
128 |
129 | SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
130 | if (sock == INVALID_SOCKET)
131 | {
132 | std::cerr << "Cannot open socket to host" << std::endl;
133 | }
134 | else
135 | {
136 | if (0 != connect(sock, (LPSOCKADDR)&target, sizeof(target)))
137 | {
138 | std::cerr << "Cannot connect to host" << std::endl;
139 | }
140 | else
141 | {
142 | send(sock, command.c_str(), static_cast(command.length()), 0);
143 | send(sock, "\n", 1, 0);
144 |
145 | while (true) // keep looping and reading blocks of memory until we find "\n" or hit an error.
146 | {
147 | const int BUFFERSIZE = 128;
148 | char buffer[BUFFERSIZE];
149 | int bytesRead = recv(sock, buffer, BUFFERSIZE, 0);
150 | if (bytesRead < 0)
151 | {
152 | std::cerr << "ERROR: Problem reading response from socket." << std::endl;
153 | break;
154 | }
155 |
156 | if (bytesRead == 0)
157 | {
158 | std::cerr << "ERROR: Incomplete response." << std::endl;
159 | break;
160 | }
161 |
162 | for (int i = 0; i < bytesRead; ++i)
163 | {
164 | if (buffer[i] == '\n')
165 | {
166 | // We found the end of the message.
167 | success = true;
168 | goto end_of_message; // break out of both loops
169 | }
170 | response.push_back(buffer[i]);
171 | }
172 | }
173 | }
174 | end_of_message:
175 | closesocket(sock);
176 | }
177 | }
178 | if (!success)
179 | {
180 | response.clear();
181 | }
182 | return success;
183 | }
184 |
--------------------------------------------------------------------------------
/chenserver/build:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # This is not quite right: should detect compiler type and version, not OS.
4 | if [[ $(uname -s) == 'Linux' ]]; then
5 | # Assume g++ build on Linux, where -stdlib=libc++ option is not allowed.
6 | CPPOPT=''
7 | else
8 | # Assume clang++ buid on Mac OS, where -stdlib=libc++ option is necessary.
9 | CPPOPT='-stdlib=libc++'
10 | fi
11 | g++ -o chenserver -std=c++0x $CPPOPT -Wall -Werror -Wextra -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual -O2 -I ../src @linux-source-files
12 |
--------------------------------------------------------------------------------
/chenserver/chenserver.h:
--------------------------------------------------------------------------------
1 | /*
2 | chenserver.h - Don Cross - http://cosinekitty.com
3 |
4 | Main header file for server version of Chenard chess engine.
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "chess.h" // pick up handy CHENARD_LINUX preprocessor symbol
16 | #if CHENARD_LINUX
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | // Hacks to help WinSock code build on Linux.
25 | typedef int SOCKET;
26 | typedef sockaddr_in SOCKADDR_IN;
27 | typedef sockaddr *LPSOCKADDR;
28 | const int INVALID_SOCKET = -1;
29 |
30 | inline bool IsValidSocket(SOCKET s)
31 | {
32 | return s >= 0;
33 | }
34 |
35 | inline int closesocket(SOCKET s)
36 | {
37 | return close(s);
38 | }
39 | #else
40 | #ifdef _MSC_VER // Windows?
41 | #include
42 |
43 | inline bool IsValidSocket(SOCKET s)
44 | {
45 | return s != INVALID_SOCKET;
46 | }
47 | #else
48 | #error We do not know how to do socket programming on this platform.
49 | #endif
50 | #endif
51 | #include "uiserver.h"
52 |
53 | class ChessGameState;
54 |
55 | enum MoveFormatKind
56 | {
57 | MOVE_FORMAT_INVALID,
58 | MOVE_FORMAT_ALGEBRAIC,
59 | MOVE_FORMAT_PGN,
60 | };
61 |
62 | inline bool StartsWith(const std::string& text, const std::string& prefix)
63 | {
64 | return
65 | (text.length() >= prefix.length()) &&
66 | (0 == text.compare(0, prefix.length(), prefix));
67 | }
68 |
69 | inline bool EndsWith(const std::string& text, const std::string& suffix)
70 | {
71 | return
72 | (text.length() >= suffix.length()) &&
73 | (0 == text.compare(text.length() - suffix.length(), suffix.length(), suffix));
74 | }
75 |
76 | void PrintUsage();
77 | MoveFormatKind ParseFormatArg(const std::vector& args, size_t& index); // use if other args may follow format
78 | bool ParseFormatArg(const std::vector& args, std::string& errorToken, MoveFormatKind& format); // use if format is only arg
79 | std::string DualMoveFormatResponse(ChessGameState& game, Move move);
80 | std::string ExecuteCommand(ChessGameState& game, ChessUI_Server& ui, const std::string& command, bool& keepRunning);
81 | std::string GameStatus(ChessGameState& game); // Forsyth Edwards Notation
82 | std::string MakeMoves(ChessGameState& game, const std::vector& moveTokenList);
83 | std::string LegalMoveList(ChessGameState& game, const std::vector& args);
84 | std::string TestLegality(ChessGameState& game, const std::string& notation);
85 | std::string Think(ChessUI_Server& ui, ChessGameState& game, int thinkTimeMillis);
86 | std::string Undo(ChessGameState& game, int numTurns);
87 | std::string History(ChessGameState& game, const std::vector& args);
88 |
89 | class ChessGameState
90 | {
91 | public:
92 | ChessGameState() {}
93 | ChessGameState(const ChessGameState&) = delete;
94 | ChessGameState& operator=(const ChessGameState&) = delete;
95 |
96 | void Reset();
97 | const char *GameResult();
98 | std::string GetForsythEdwardsNotation();
99 | std::string FormatAlg(Move move); // caller must pass only verified legal moves
100 | std::string FormatPgn(Move move); // caller must pass only verified legal moves
101 | std::string Format(Move move, MoveFormatKind format); // caller must pass only verified legal moves, and must pass valid format specifier
102 | std::vector History(MoveFormatKind format);
103 | bool ParseMove(const std::string& notation, Move& move); // returns true only if notation represents legal move
104 | int NumTurns() const { return static_cast(moveStack.size()); }
105 | void PushMove(Move move); // caller must pass only verified legal moves
106 | void PopMove();
107 | int GenMoves(MoveList& ml) { return board.GenMoves(ml); }
108 | bool Think(ChessUI_Server& ui, int thinkTimeMillis, Move& move);
109 | bool IsGameOver() { return board.GameIsOver(); }
110 |
111 | private:
112 | struct MoveState
113 | {
114 | Move move;
115 | UnmoveInfo unmove;
116 |
117 | MoveState(const Move& _move, const UnmoveInfo& _unmove)
118 | : move(_move)
119 | , unmove(_unmove)
120 | {}
121 | };
122 |
123 | ChessBoard board;
124 | std::vector moveStack;
125 | };
126 |
127 | /*
128 | ChessCommandInterface is an abstract class representing
129 | a way of sending and receiving strings of text commands.
130 | */
131 | class ChessCommandInterface
132 | {
133 | public:
134 | virtual ~ChessCommandInterface() {}
135 | virtual bool ReadLine(std::string& line, bool& keepRunning) = 0;
136 | virtual void WriteLine(const std::string& line) = 0;
137 | };
138 |
139 | class ChessCommandInterface_stdio : public ChessCommandInterface
140 | {
141 | public:
142 | ChessCommandInterface_stdio();
143 | ChessCommandInterface_stdio(const ChessCommandInterface_stdio&) = delete;
144 | ChessCommandInterface_stdio& operator= (const ChessCommandInterface_stdio&) = delete;
145 | virtual ~ChessCommandInterface_stdio();
146 | virtual bool ReadLine(std::string& line, bool& keepRunning);
147 | virtual void WriteLine(const std::string& line);
148 | };
149 |
150 | class ChessCommandInterface_tcp : public ChessCommandInterface
151 | {
152 | public:
153 | explicit ChessCommandInterface_tcp(int _port);
154 | ChessCommandInterface_tcp(const ChessCommandInterface_tcp&) = delete;
155 | ChessCommandInterface_tcp& operator= (const ChessCommandInterface_tcp&) = delete;
156 | virtual ~ChessCommandInterface_tcp();
157 | virtual bool ReadLine(std::string& line, bool& keepRunning);
158 | virtual void WriteLine(const std::string& line);
159 |
160 | private:
161 | const int port;
162 | #ifdef _MSC_VER
163 | bool initialized;
164 | #endif
165 | bool ready;
166 | SOCKET hostSocket;
167 | SOCKET clientSocket;
168 | enum data_mode { MODE_LINE, MODE_HTTP } mode;
169 | char httpMinorVersion;
170 |
171 |
172 | void CloseSocket(SOCKET &sock)
173 | {
174 | if (IsValidSocket(sock))
175 | {
176 | ::closesocket(sock);
177 | sock = INVALID_SOCKET;
178 | }
179 | }
180 |
181 | std::string UrlDecode(const std::string& urltext);
182 | };
183 |
--------------------------------------------------------------------------------
/chenserver/chenserver.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 | {2f717ebc-e51b-4390-a1fa-62002477850e}
18 |
19 |
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files\engine
32 |
33 |
34 | Source Files\engine
35 |
36 |
37 | Source Files\engine
38 |
39 |
40 | Source Files\engine
41 |
42 |
43 | Source Files\engine
44 |
45 |
46 | Source Files\engine
47 |
48 |
49 | Source Files\engine
50 |
51 |
52 | Source Files\engine
53 |
54 |
55 | Source Files\engine
56 |
57 |
58 | Source Files\engine
59 |
60 |
61 | Source Files\engine
62 |
63 |
64 | Source Files\engine
65 |
66 |
67 | Source Files\engine
68 |
69 |
70 | Source Files\engine
71 |
72 |
73 | Source Files\engine
74 |
75 |
76 | Source Files\engine
77 |
78 |
79 | Source Files\engine
80 |
81 |
82 | Source Files\engine
83 |
84 |
85 | Source Files\engine
86 |
87 |
88 | Source Files\engine
89 |
90 |
91 | Source Files\engine
92 |
93 |
94 | Source Files\engine
95 |
96 |
97 | Source Files\engine
98 |
99 |
100 | Source Files\engine
101 |
102 |
103 | Source Files\engine
104 |
105 |
106 | Source Files\engine
107 |
108 |
109 | Source Files\engine
110 |
111 |
112 | Source Files\engine
113 |
114 |
115 | Source Files\engine
116 |
117 |
118 | Source Files
119 |
120 |
121 | Source Files\engine
122 |
123 |
124 | Source Files
125 |
126 |
127 |
128 |
129 | Header Files
130 |
131 |
132 | Header Files
133 |
134 |
135 | Header Files
136 |
137 |
138 | Header Files
139 |
140 |
141 | Header Files
142 |
143 |
144 | Header Files
145 |
146 |
147 | Header Files
148 |
149 |
150 | Header Files
151 |
152 |
153 |
--------------------------------------------------------------------------------
/chenserver/gamestate.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | gamestate.cpp - Don Cross - http://cosinekitty.com
3 | */
4 |
5 | #include "chenserver.h"
6 |
7 | void ChessGameState::Reset()
8 | {
9 | board.Init();
10 | moveStack.clear();
11 | }
12 |
13 | const char * ChessGameState::GameResult()
14 | {
15 | const char *result = "*"; // assume the game is not over yet, unless we find otherwise.
16 | if (board.GameIsOver())
17 | {
18 | if (board.CurrentPlayerInCheck())
19 | {
20 | result = board.WhiteToMove() ? "0-1" : "1-0"; // Whoever has the move just lost.
21 | }
22 | else
23 | {
24 | result = "1/2-1/2";
25 | }
26 | }
27 | return result;
28 | }
29 |
30 | std::string ChessGameState::GetForsythEdwardsNotation()
31 | {
32 | char buffer[200];
33 | if (nullptr == board.GetForsythEdwardsNotation(buffer, sizeof(buffer)))
34 | {
35 | assert(false); // this should never happen!
36 | return "BADFEN";
37 | }
38 | return std::string(buffer);
39 | }
40 |
41 | bool ChessGameState::ParseMove(const std::string& notation, Move& move)
42 | {
43 | if (::ParseFancyMove(notation.c_str(), board, move))
44 | {
45 | if (board.isLegal(move))
46 | {
47 | return true;
48 | }
49 | assert(false); // internal error: ParseFancyMove should not have returned true for an illegal move!
50 | }
51 | return false;
52 | }
53 |
54 | std::string ChessGameState::FormatAlg(Move move)
55 | {
56 | char algebraic[LONGMOVE_MAX_CHARS];
57 | if (!::FormatLongMove(board.WhiteToMove(), move, algebraic))
58 | {
59 | assert(false);
60 | return "BADALG";
61 | }
62 | return std::string(algebraic);
63 | }
64 |
65 | std::string ChessGameState::FormatPgn(Move move)
66 | {
67 | if (board.isLegal(move))
68 | {
69 | char pgn[MAX_MOVE_STRLEN + 1];
70 | ::FormatChessMove(board, move, pgn);
71 | return std::string(pgn);
72 | }
73 | assert(false); // caller should not have passed an illegal move
74 | return "BADPGN";
75 | }
76 |
77 | std::string ChessGameState::Format(Move move, MoveFormatKind format)
78 | {
79 | switch (format)
80 | {
81 | case MOVE_FORMAT_ALGEBRAIC:
82 | return FormatAlg(move);
83 |
84 | case MOVE_FORMAT_PGN:
85 | return FormatPgn(move);
86 |
87 | default:
88 | assert(false); // caller should verify format
89 | return "BAD_FORMAT";
90 | }
91 | }
92 |
93 | std::vector ChessGameState::History(MoveFormatKind format)
94 | {
95 | using namespace std;
96 |
97 | // Every time we format a move, we need the board to be in the state it was
98 | // just before that move was made.
99 | // Pop all the moves from the move stack one by one and push onto 'revStack'.
100 | // This has the effect of reversing the order of the moves as we rewind
101 | // the board back to its initial state.
102 | vector revStack;
103 | while (moveStack.size() > 0)
104 | {
105 | MoveState m = moveStack.back();
106 | moveStack.pop_back();
107 | revStack.push_back(m);
108 | board.UnmakeMove(m.move, m.unmove);
109 | }
110 |
111 | // When we get here, 'revStack' has the earliest moves at the back
112 | // and the most recent moves to the front.
113 | // Now we make the moves in forward order so that we can format each move.
114 | vector history;
115 | while (revStack.size() > 0)
116 | {
117 | MoveState m = revStack.back();
118 | revStack.pop_back();
119 | moveStack.push_back(m);
120 | history.push_back(Format(m.move, format));
121 | board.MakeMove(m.move, m.unmove);
122 | }
123 |
124 | return history;
125 | }
126 |
127 | void ChessGameState::PushMove(Move move)
128 | {
129 | if (board.isLegal(move))
130 | {
131 | UnmoveInfo unmove;
132 | board.MakeMove(move, unmove);
133 | moveStack.push_back(MoveState(move, unmove));
134 | }
135 | else
136 | {
137 | assert(false); // caller must pass only verified legal moves
138 | }
139 | }
140 |
141 | void ChessGameState::PopMove()
142 | {
143 | assert(moveStack.size() > 0);
144 | if (moveStack.size() > 0)
145 | {
146 | MoveState tail = moveStack.back();
147 | board.UnmakeMove(tail.move, tail.unmove);
148 | moveStack.pop_back();
149 | }
150 | }
151 |
152 | bool ChessGameState::Think(ChessUI_Server& ui, int thinkTimeMillis, Move& move)
153 | {
154 | int centis = (thinkTimeMillis + 9) / 10; // convert milliseconds to centiseconds and round up
155 | ComputerChessPlayer thinker(ui);
156 | thinker.setResignFlag(false); // do not allow computer to resign
157 | thinker.SetTimeLimit(centis); // set upper limit on how long computer is allowed to think
158 | INT32 timeSpent = 0;
159 | return thinker.GetMove(board, move, timeSpent);
160 | }
--------------------------------------------------------------------------------
/chenserver/ifstdio.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | ifstdio.cpp - Don Cross - http://cosinekitty.com
3 | */
4 |
5 | #include "chenserver.h"
6 |
7 | ChessCommandInterface_stdio::ChessCommandInterface_stdio()
8 | {
9 | }
10 |
11 |
12 | ChessCommandInterface_stdio::~ChessCommandInterface_stdio()
13 | {
14 | }
15 |
16 |
17 | bool ChessCommandInterface_stdio::ReadLine(std::string& line, bool& keepRunning)
18 | {
19 | line.clear();
20 | keepRunning = !!std::getline(std::cin, line); // stop running when we hit EOF
21 | return keepRunning;
22 | }
23 |
24 |
25 | void ChessCommandInterface_stdio::WriteLine(const std::string& line)
26 | {
27 | std::cout << line << std::endl;
28 | }
29 |
--------------------------------------------------------------------------------
/chenserver/linux-source-files:
--------------------------------------------------------------------------------
1 | chenserver.cpp
2 | gamestate.cpp
3 | ifstdio.cpp
4 | iftcp.cpp
5 | uiserver.cpp
6 | ../src/attack.cpp
7 | ../src/board.cpp
8 | ../src/canmove.cpp
9 | ../src/chenga.cpp
10 | ../src/chengene.cpp
11 | ../src/crand.cpp
12 | ../src/egdbase.cpp
13 | ../src/endgame.cpp
14 | ../src/eval.cpp
15 | ../src/fancy.cpp
16 | ../src/game.cpp
17 | ../src/gamefile.cpp
18 | ../src/gencaps.cpp
19 | ../src/genmove.cpp
20 | ../src/human.cpp
21 | ../src/lichess.cpp
22 | ../src/linuxtime.cpp
23 | ../src/lrntree.cpp
24 | ../src/material.cpp
25 | ../src/misc.cpp
26 | ../src/morder.cpp
27 | ../src/move.cpp
28 | ../src/openbook.cpp
29 | ../src/opening.cpp
30 | ../src/player.cpp
31 | ../src/search.cpp
32 | ../src/textundo.cpp
33 | ../src/transpos.cpp
34 | ../src/ui.cpp
35 | ../src/unmove.cpp
36 |
37 |
--------------------------------------------------------------------------------
/chenserver/uiserver.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | uiserver.cpp - Don Cross - http://cosinekitty.com
3 | */
4 |
5 | #include "chenserver.h"
6 |
7 | ChessUI_Server::ChessUI_Server()
8 | {
9 | }
10 |
11 | ChessUI_Server::~ChessUI_Server()
12 | {
13 | }
14 |
15 | ChessPlayer* ChessUI_Server::CreatePlayer(ChessSide)
16 | {
17 | // This function should never be called because chenserver does not use the ChessGame class.
18 | ChessFatal("ChessUI_Server::CreatePlayer() should not have been called!");
19 | return nullptr;
20 | }
21 |
22 | void ChessUI_Server::ReportEndOfGame(ChessSide /*winner*/)
23 | {
24 | // Nothing to do here.
25 | }
26 |
27 | void ChessUI_Server::Resign(ChessSide, QuitGameReason)
28 | {
29 | // Do we need this?
30 | }
31 |
32 | bool ChessUI_Server::ReadMove(
33 | ChessBoard &,
34 | int & /*source*/,
35 | int & /*dest*/,
36 | SQUARE & /*promPieceIndex*/)
37 | {
38 | ChessFatal("ChessUI_Server::ReadMove() should not have been called!");
39 | return false;
40 | }
41 |
42 | SQUARE ChessUI_Server::PromotePawn(int /*PawnSource*/, int /*PawnDest*/, ChessSide)
43 | {
44 | ChessFatal("ChessUI_Server::PromotePawn() should not have been called!");
45 | return 0;
46 | }
47 |
48 | void ChessUI_Server::DisplayMove(ChessBoard &, Move)
49 | {
50 | // Nothing to do here.
51 | }
52 |
53 | void ChessUI_Server::RecordMove(ChessBoard &, Move, INT32 /*thinkTime*/)
54 | {
55 | ChessFatal("ChessUI_Server::RecordMove() should not have been called!");
56 | }
57 |
58 | void ChessUI_Server::ReportComputerStats(
59 | INT32 /*thinkTime*/,
60 | UINT32 /*nodesVisited*/,
61 | UINT32 /*nodesEvaluated*/,
62 | UINT32 /*nodesGenerated*/,
63 | int /*fwSearchDepth*/,
64 | UINT32 /*vis*/ [NODES_ARRAY_SIZE],
65 | UINT32 /*gen*/ [NODES_ARRAY_SIZE])
66 | {
67 | // Nothing to do here.
68 | }
69 |
70 | void ChessUI_Server::DrawBoard(const ChessBoard &)
71 | {
72 | // Nothing to do.
73 | }
74 |
75 | void ChessUI_Server::NotifyUser(const char * /*message*/)
76 | {
77 | // Nothing to do.
78 | }
79 |
80 | void ChessUI_Server::DisplayBestMoveSoFar(
81 | const ChessBoard &,
82 | Move,
83 | int /*level*/)
84 | {
85 | }
86 |
87 | void ChessUI_Server::DisplayCurrentMove(
88 | const ChessBoard &,
89 | Move,
90 | int /*level*/)
91 | {
92 | }
93 |
94 | void ChessUI_Server::PredictMate(int /*numMovesFromNow*/)
95 | {
96 | }
97 |
--------------------------------------------------------------------------------
/chenserver/uiserver.h:
--------------------------------------------------------------------------------
1 | /*
2 | uiserver.h - Don Cross - http://cosinekitty.com
3 |
4 | Derived user interface class for chenserver.
5 | */
6 |
7 | class ChessUI_Server : public ChessUI
8 | {
9 | public:
10 | ChessUI_Server();
11 | virtual ~ChessUI_Server();
12 |
13 | virtual ChessPlayer *CreatePlayer(ChessSide);
14 |
15 | // NOTE: The following is called only when there is a
16 | // checkmate, stalemate, or draw by attrition.
17 | // The function is NOT called if a player resigns.
18 | virtual void ReportEndOfGame(ChessSide winner);
19 |
20 | virtual void Resign(ChessSide iGiveUp, QuitGameReason);
21 |
22 | //--------------------------------------------------------------
23 | // The following function should return true if the Move
24 | // was read successfully, or false to abort the game.
25 | // The move does not have to be legal; if an illegal move
26 | // is returned, the caller will repeatedly call until a
27 | // legal move is obtained.
28 | //--------------------------------------------------------------
29 | virtual bool ReadMove(
30 | ChessBoard &board,
31 | int &source,
32 | int &dest,
33 | SQUARE &promPieceIndex // set to 0 (P_INDEX) if no promotion, or call to PromotePawn is needed; set to N_INDEX..Q_INDEX to specify promotion.
34 | );
35 |
36 | //--------------------------------------------------------------
37 | // Called whenever a player needs to be asked which
38 | // piece a pawn should be promoted to.
39 | // Must return one of the following values:
40 | // Q_INDEX, R_INDEX, B_INDEX, N_INDEX
41 | //--------------------------------------------------------------
42 | virtual SQUARE PromotePawn(int PawnSource, int PawnDest, ChessSide);
43 |
44 | //--------------------------------------------------------------
45 | // The following function should display the given Move
46 | // in the context of the given ChessBoard. The Move
47 | // passed to this function will always be legal for the
48 | // given ChessBoard.
49 | //
50 | // The purpose of this function is for a non-human ChessPlayer
51 | // to have a chance to animate the chess board.
52 | // The ChessGame does not call this function; it is up
53 | // to a particular kind of ChessPlayer to do so if needed.
54 | //--------------------------------------------------------------
55 | virtual void DisplayMove(ChessBoard &, Move);
56 |
57 | //----------------------------------------------------------------
58 | // The following function is called by the ChessGame after
59 | // each player moves, so that the move can be displayed
60 | // in standard chess notation, if the UI desires.
61 | // It is helpful to use the ::FormatChessMove() function
62 | // for this purpose.
63 | // The parameter 'thinkTime' is how long the player thought
64 | // about the move, expressed in hundredths of seconds.
65 | //
66 | // NOTE: This function is called BEFORE the move
67 | // has been made on the given ChessBoard.
68 | // This is necessary for ::FormatChessMove() to work.
69 | //----------------------------------------------------------------
70 | virtual void RecordMove(ChessBoard &, Move, INT32 thinkTime);
71 |
72 | virtual void ReportComputerStats(
73 | INT32 thinkTime,
74 | UINT32 nodesVisited,
75 | UINT32 nodesEvaluated,
76 | UINT32 nodesGenerated,
77 | int fwSearchDepth,
78 | UINT32 vis[NODES_ARRAY_SIZE],
79 | UINT32 gen[NODES_ARRAY_SIZE]);
80 |
81 | //--------------------------------------------------------------//
82 | // The following function should display the given ChessBoard //
83 | // to the user. //
84 | // In a GUI, this means updating the board display to the //
85 | // given board's contents. //
86 | // In TTY-style UI, this means printing out a new board. //
87 | //--------------------------------------------------------------//
88 | virtual void DrawBoard(const ChessBoard &);
89 |
90 | //----------------------------------------------------------------
91 | // The following member function displays a prompt and waits
92 | // for acknowledgement from the user.
93 | //----------------------------------------------------------------
94 | virtual void NotifyUser(const char *message);
95 |
96 | virtual void DisplayBestMoveSoFar(
97 | const ChessBoard &,
98 | Move,
99 | int level);
100 |
101 | virtual void DisplayCurrentMove(
102 | const ChessBoard &,
103 | Move,
104 | int level);
105 |
106 | // The ComputerChessPlayer calls this to announce that it
107 | // has found a forced mate.
108 |
109 | virtual void PredictMate(int numMovesFromNow);
110 | };
111 |
--------------------------------------------------------------------------------
/fen/.idea/jsLibraryMappings.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/fen/.idea/typescript-compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/fen/bitmap/bbb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bbb.png
--------------------------------------------------------------------------------
/fen/bitmap/bbk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bbk.png
--------------------------------------------------------------------------------
/fen/bitmap/bbn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bbn.png
--------------------------------------------------------------------------------
/fen/bitmap/bbp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bbp.png
--------------------------------------------------------------------------------
/fen/bitmap/bbq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bbq.png
--------------------------------------------------------------------------------
/fen/bitmap/bbr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bbr.png
--------------------------------------------------------------------------------
/fen/bitmap/bsq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bsq.png
--------------------------------------------------------------------------------
/fen/bitmap/bwb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bwb.png
--------------------------------------------------------------------------------
/fen/bitmap/bwk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bwk.png
--------------------------------------------------------------------------------
/fen/bitmap/bwn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bwn.png
--------------------------------------------------------------------------------
/fen/bitmap/bwp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bwp.png
--------------------------------------------------------------------------------
/fen/bitmap/bwq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bwq.png
--------------------------------------------------------------------------------
/fen/bitmap/bwr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/bwr.png
--------------------------------------------------------------------------------
/fen/bitmap/wbb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wbb.png
--------------------------------------------------------------------------------
/fen/bitmap/wbk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wbk.png
--------------------------------------------------------------------------------
/fen/bitmap/wbn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wbn.png
--------------------------------------------------------------------------------
/fen/bitmap/wbp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wbp.png
--------------------------------------------------------------------------------
/fen/bitmap/wbq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wbq.png
--------------------------------------------------------------------------------
/fen/bitmap/wbr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wbr.png
--------------------------------------------------------------------------------
/fen/bitmap/wsq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wsq.png
--------------------------------------------------------------------------------
/fen/bitmap/wwb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wwb.png
--------------------------------------------------------------------------------
/fen/bitmap/wwk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wwk.png
--------------------------------------------------------------------------------
/fen/bitmap/wwn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wwn.png
--------------------------------------------------------------------------------
/fen/bitmap/wwp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wwp.png
--------------------------------------------------------------------------------
/fen/bitmap/wwq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wwq.png
--------------------------------------------------------------------------------
/fen/bitmap/wwr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/fen/bitmap/wwr.png
--------------------------------------------------------------------------------
/fen/fen.ts:
--------------------------------------------------------------------------------
1 | /* fen.ts - Don Cross - http://cosinekitty.com */
2 |
3 | module fen {
4 | export enum ChessSquare {
5 | EMPTY,
6 |
7 | WPAWN,
8 | WKNIGHT,
9 | WBISHOP,
10 | WROOK,
11 | WQUEEN,
12 | WKING,
13 |
14 | BPAWN,
15 | BKNIGHT,
16 | BBISHOP,
17 | BROOK,
18 | BQUEEN,
19 | BKING,
20 | }
21 |
22 | export class ChessBoard {
23 | private squares: ChessSquare[];
24 |
25 | constructor(fentext: string) {
26 | // r1bqkb1r/pppp1ppp/2n2n2/1B2p3/4P3/5N2/PPPP1PPP/RNBQ1RK1 b kq - 5 4
27 |
28 | this.squares = [];
29 |
30 | // Split FEN text into space-delimited tokens.
31 | var stokens:string[] = fentext.split(' ');
32 |
33 | // Let's be pretty tolerant. We care only about the board layout, so search
34 | // for it. Assume it is the first token that contains a forward slash.
35 | var i:number;
36 | var layout:string = null;
37 | for (i=0; i < stokens.length; ++i) {
38 | if (stokens[i].indexOf('/') > 0) { // note we exclude beginning with a slash on purpose
39 | layout = stokens[i];
40 | break;
41 | }
42 | }
43 | if (layout === null) {
44 | throw 'Cannot find board layout in FEN text.';
45 | }
46 |
47 | // Prevent abuse by checking for excessive layout length.
48 | // The longest possible layout would have 8 ranks with 8 characters each,
49 | // with 7 slashes separating them.
50 | if (layout.length > 8*8 + 7) {
51 | throw 'Invalid FEN layout: too many characters.';
52 | }
53 |
54 | // Split the FEN text into 8 ranks.
55 | var ranks:string[] = layout.split('/');
56 | if (ranks.length != 8) {
57 | throw 'Invalid FEN layout: must have exactly 8 ranks.';
58 | }
59 |
60 | // Process the ranks backwards, so that we handle White's side of the board first.
61 | var r:number;
62 | var numEmpty:number;
63 | var c:string;
64 | var rowcount:number;
65 | for (r=7; r >= 0; --r) {
66 | // Decode each rank string into 8 squares.
67 | rowcount = 0;
68 | for (i=0; i < ranks[r].length; ++i) {
69 | ++rowcount;
70 | switch (c = ranks[r].charAt(i)) {
71 | case 'P': this.squares.push(ChessSquare.WPAWN); break;
72 | case 'N': this.squares.push(ChessSquare.WKNIGHT); break;
73 | case 'B': this.squares.push(ChessSquare.WBISHOP); break;
74 | case 'R': this.squares.push(ChessSquare.WROOK); break;
75 | case 'Q': this.squares.push(ChessSquare.WQUEEN); break;
76 | case 'K': this.squares.push(ChessSquare.WKING); break;
77 | case 'p': this.squares.push(ChessSquare.BPAWN); break;
78 | case 'n': this.squares.push(ChessSquare.BKNIGHT); break;
79 | case 'b': this.squares.push(ChessSquare.BBISHOP); break;
80 | case 'r': this.squares.push(ChessSquare.BROOK); break;
81 | case 'q': this.squares.push(ChessSquare.BQUEEN); break;
82 | case 'k': this.squares.push(ChessSquare.BKING); break;
83 | case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8':
84 | rowcount += (+c - 1);
85 | for (numEmpty = +c; numEmpty > 0; --numEmpty) {
86 | this.squares.push(ChessSquare.EMPTY);
87 | }
88 | break;
89 | default:
90 | throw 'Invalid character in FEN layout text.';
91 | }
92 | }
93 | if (rowcount != 8) {
94 | throw 'Invalid number of pieces in row: ' + ranks[r];
95 | }
96 | }
97 |
98 | if (this.squares.length != 64) {
99 | throw 'Invalid number of squares encoded by FEN layout text: must be 64.';
100 | }
101 | }
102 |
103 | public Square(x:number, y:number): ChessSquare {
104 | ChessBoard.ValidateCoord(x);
105 | ChessBoard.ValidateCoord(y);
106 | return this.squares[(8*y) + x];
107 | }
108 |
109 | private static ValidateCoord(n:number):void {
110 | if (!ChessBoard.IsValidCoord(n)) {
111 | throw "Chess board coordinates must both be integers in the range 0..7.";
112 | }
113 | }
114 |
115 | private static IsValidCoord(n:number): boolean {
116 | return ChessBoard.IsInteger(n) && (n >= 0) && (n <= 7);
117 | }
118 |
119 | private static IsInteger(n:number): boolean {
120 | return !isNaN(n) && ((n | 0) === n);
121 | }
122 |
123 | public ImageFileName(x:number, y:number): string {
124 | var sq = this.Square(x, y); // will validate coordinates for us
125 | var bg:string = 'bw'.charAt((x+y) & 1); // square background color code: 'b' or 'w'
126 | switch (sq) {
127 | case ChessSquare.WPAWN: return bg + 'wp.png';
128 | case ChessSquare.WKNIGHT: return bg + 'wn.png';
129 | case ChessSquare.WBISHOP: return bg + 'wb.png';
130 | case ChessSquare.WROOK: return bg + 'wr.png';
131 | case ChessSquare.WQUEEN: return bg + 'wq.png';
132 | case ChessSquare.WKING: return bg + 'wk.png';
133 | case ChessSquare.BPAWN: return bg + 'bp.png';
134 | case ChessSquare.BKNIGHT: return bg + 'bn.png';
135 | case ChessSquare.BBISHOP: return bg + 'bb.png';
136 | case ChessSquare.BROOK: return bg + 'br.png';
137 | case ChessSquare.BQUEEN: return bg + 'bq.png';
138 | case ChessSquare.BKING: return bg + 'bk.png';
139 | default: return bg + 'sq.png';
140 | }
141 | }
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/fen/fentool.css:
--------------------------------------------------------------------------------
1 | /* fentool.css - Don Cross - http://cosinekitty.com */
2 |
3 | .RankFileText {
4 | font-family: monospace;
5 | }
6 |
7 | .FenEditBox {
8 | font-family: monospace;
9 | font-size: smaller;
10 | }
--------------------------------------------------------------------------------
/fen/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Forsyth-Edwards Notation display tool
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 |
--------------------------------------------------------------------------------
/fen/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "removeComments": false,
4 | "sourceMap": true
5 | },
6 |
7 | "files": [
8 | "fen.ts",
9 | "ui.ts"
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/fen/ui.ts:
--------------------------------------------------------------------------------
1 | /* ui.ts - Don Cross - http://cosinekitty.com */
2 |
3 | ///
4 | ///
5 |
6 | var RotateFlag:boolean = false;
7 | var SquarePixels:number = 44;
8 |
9 | function MakeImageContainer(x:number, y:number): string {
10 | return '';
14 | }
15 |
16 | function MakeImageHtml(filename:string): string {
17 | return '
';
18 | }
19 |
20 | function MakeFileLabel(x:number): string {
21 | return 'x
';
24 | }
25 |
26 | function MakeRankLabel(y:number): string {
27 | return 'y
';
31 | }
32 |
33 | function InitBoardDisplay() {
34 | var x:number;
35 | var y:number;
36 | var html:string = '';
37 | for (y=7; y>=0; --y) {
38 | for (x=0; x<8; ++x) {
39 | html += MakeImageContainer(x, y);
40 | }
41 | }
42 | for (x=0; x<8; ++x) {
43 | html += MakeFileLabel(x);
44 | }
45 | for (y=0; y<8; ++y) {
46 | html += MakeRankLabel(y);
47 | }
48 | $('#DivBoard').html(html);
49 | ResetBoard();
50 | }
51 |
52 | function ResetBoard() {
53 | SetBoard('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR');
54 | }
55 |
56 | function SetBoard(text:string):boolean {
57 | if (UpdateBoard(text)) {
58 | $('#TextBoxFen').val(text);
59 | return true;
60 | }
61 | return false;
62 | }
63 |
64 | function UpdateBoard(text:string):boolean {
65 | $('#DivErrorText').text('');
66 | var board: fen.ChessBoard;
67 | try {
68 | board = new fen.ChessBoard(text);
69 | } catch (ex) {
70 | ClearBoard(); // must clear before setting error text, because this will clear the error text!
71 | $('#DivErrorText').text(ex);
72 | return false;
73 | }
74 |
75 | var x, rx, y, ry:number;
76 | var imageFileName: string;
77 | for (y=0; y < 8; ++y) {
78 | ry = RotateFlag ? (7-y) : y;
79 | $('#RankLabel_' + ry.toFixed()).text('87654321'.charAt(y));
80 | $('#FileLabel_' + ry.toFixed()).text('abcdefgh'.charAt(y));
81 | for (x=0; x < 8; ++x) {
82 | rx = RotateFlag ? (7-x) : x;
83 | imageFileName = 'bitmap/' + board.ImageFileName(x, y);
84 | $('#Square_' + rx.toString() + ry.toString()).html(MakeImageHtml(imageFileName));
85 | }
86 | }
87 | return true;
88 | }
89 |
90 | function ClearBoard():void {
91 | UpdateBoard('8/8/8/8/8/8/8/8');
92 | }
93 |
94 | $(function(){
95 | var textBoxFen = $('#TextBoxFen');
96 |
97 | $('#ButtonDisplay').click(function(){
98 | UpdateBoard(textBoxFen.prop('value'));
99 | });
100 |
101 | textBoxFen.click(function(){
102 | $(this).select();
103 | }).keyup(function(e){
104 | if (e.keyCode == 13) {
105 | UpdateBoard(textBoxFen.prop('value'));
106 | $(this).select();
107 | }
108 | });
109 |
110 | $('#ButtonRotate').click(function(){
111 | RotateFlag = !RotateFlag;
112 | UpdateBoard(textBoxFen.prop('value'));
113 | });
114 |
115 | $('#ButtonReset').click(function(){
116 | ResetBoard();
117 | });
118 |
119 | $('#ButtonClear').click(function(){
120 | SetBoard('8/8/8/8/8/8/8/8');
121 | });
122 |
123 | InitBoardDisplay();
124 | });
125 |
--------------------------------------------------------------------------------
/images/README.md:
--------------------------------------------------------------------------------
1 | These chess piece images were obtained from:
2 |
3 | https://github.com/ornicar/lila/tree/master/public/piece/cburnett
4 |
5 | I used InkScape to convert the SVG files to PNG.
6 |
7 |
--------------------------------------------------------------------------------
/images/bb.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bb.bmp
--------------------------------------------------------------------------------
/images/bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bb.png
--------------------------------------------------------------------------------
/images/bb.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/bk.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bk.bmp
--------------------------------------------------------------------------------
/images/bk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bk.png
--------------------------------------------------------------------------------
/images/bk.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/bn.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bn.bmp
--------------------------------------------------------------------------------
/images/bn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bn.png
--------------------------------------------------------------------------------
/images/bn.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/bp.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bp.bmp
--------------------------------------------------------------------------------
/images/bp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bp.png
--------------------------------------------------------------------------------
/images/bp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/bq.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bq.bmp
--------------------------------------------------------------------------------
/images/bq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/bq.png
--------------------------------------------------------------------------------
/images/bq.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/br.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/br.bmp
--------------------------------------------------------------------------------
/images/br.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/br.png
--------------------------------------------------------------------------------
/images/br.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/makepng:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | Fail()
3 | {
4 | echo "FATAL($0): $1"
5 | exit 1
6 | }
7 |
8 | type inkscape > /dev/null || Fail "inkscape is not installed"
9 |
10 | SIZE=72
11 | rm -f *.png
12 | for PIECE in wk wq wr wb wn wp bk bq br bb bn bp; do
13 | inkscape -z -w ${SIZE} -h ${SIZE} ${PIECE}.svg -e ${PIECE}.png || Fail "inkscape command failed for ${PIECE}.svg"
14 | done
15 | exit 0
16 |
--------------------------------------------------------------------------------
/images/wb.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wb.bmp
--------------------------------------------------------------------------------
/images/wb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wb.png
--------------------------------------------------------------------------------
/images/wb.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/wk.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wk.bmp
--------------------------------------------------------------------------------
/images/wk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wk.png
--------------------------------------------------------------------------------
/images/wk.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/wn.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wn.bmp
--------------------------------------------------------------------------------
/images/wn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wn.png
--------------------------------------------------------------------------------
/images/wn.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/wp.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wp.bmp
--------------------------------------------------------------------------------
/images/wp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wp.png
--------------------------------------------------------------------------------
/images/wp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/wq.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wq.bmp
--------------------------------------------------------------------------------
/images/wq.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wq.png
--------------------------------------------------------------------------------
/images/wq.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/images/wr.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wr.bmp
--------------------------------------------------------------------------------
/images/wr.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/images/wr.png
--------------------------------------------------------------------------------
/images/wr.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/linux/build:
--------------------------------------------------------------------------------
1 | cd ../src
2 | g++ -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual -O2 -o ../linux/chenard @../linux/sourcefiles
3 | cd ../linux
4 |
--------------------------------------------------------------------------------
/linux/run:
--------------------------------------------------------------------------------
1 | xboard -debug -fcp ./xchenard -scp ./xchenard -size medium
2 |
--------------------------------------------------------------------------------
/linux/sourcefiles:
--------------------------------------------------------------------------------
1 | attack.cpp
2 | board.cpp
3 | canmove.cpp
4 | chenga.cpp
5 | chengene.cpp
6 | crand.cpp
7 | egdbase.cpp
8 | endgame.cpp
9 | eval.cpp
10 | fancy.cpp
11 | game.cpp
12 | gamefile.cpp
13 | gencaps.cpp
14 | genmove.cpp
15 | human.cpp
16 | lichess.cpp
17 | linuxtime.cpp
18 | lrntree.cpp
19 | material.cpp
20 | misc.cpp
21 | morder.cpp
22 | move.cpp
23 | openbook.cpp
24 | opening.cpp
25 | player.cpp
26 | portable.cpp
27 | search.cpp
28 | textundo.cpp
29 | transpos.cpp
30 | ui.cpp
31 | uistdio.cpp
32 | unmove.cpp
33 |
--------------------------------------------------------------------------------
/linux/vgbuild:
--------------------------------------------------------------------------------
1 | cd ../src
2 | g++ -g -O0 -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual -o ../linux/vgchenard @../linux/sourcefiles
3 | cd ../linux
4 |
--------------------------------------------------------------------------------
/linux/vgtest:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | valgrind --leak-check=yes ./vgchenard
3 |
--------------------------------------------------------------------------------
/linux/xbuild:
--------------------------------------------------------------------------------
1 | cd ../src
2 | g++ -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual -O2 -o ../linux/xchenard @../linux/xsourcefiles
3 | cd ../linux
4 |
--------------------------------------------------------------------------------
/linux/xsourcefiles:
--------------------------------------------------------------------------------
1 | xchenard.cpp
2 | uixboard.cpp
3 | attack.cpp
4 | board.cpp
5 | canmove.cpp
6 | chenga.cpp
7 | chengene.cpp
8 | crand.cpp
9 | egdbase.cpp
10 | endgame.cpp
11 | eval.cpp
12 | fancy.cpp
13 | game.cpp
14 | gamefile.cpp
15 | gencaps.cpp
16 | genmove.cpp
17 | human.cpp
18 | lichess.cpp
19 | linuxtime.cpp
20 | lrntree.cpp
21 | material.cpp
22 | misc.cpp
23 | morder.cpp
24 | move.cpp
25 | openbook.cpp
26 | opening.cpp
27 | player.cpp
28 | search.cpp
29 | textundo.cpp
30 | transpos.cpp
31 | ui.cpp
32 | unmove.cpp
33 |
--------------------------------------------------------------------------------
/openbook/contain.h:
--------------------------------------------------------------------------------
1 | /*===========================================================================
2 |
3 | contain.h - Don Cross, August 1993.
4 |
5 | New container templates.
6 |
7 | Revision history:
8 |
9 | 1994 January 27 [Don Cross]
10 | Fixed bug in List<>::removeFromBack(): the index should
11 | be numItems()-1, not numItems().
12 |
13 | ===========================================================================*/
14 |
15 | #ifndef __DDC_CONTAIN_H
16 | #define __DDC_CONTAIN_H
17 |
18 | #include "ddc.h"
19 |
20 | class LinkedImplementation;
21 |
22 | template
23 | class List
24 | {
25 | public:
26 | virtual ~List();
27 |
28 | void reset();
29 |
30 | unsigned numItems() const {return vpList.numItems();}
31 |
32 | Item & operator[] ( unsigned i ) const {return *(Item *)(vpList[i]);}
33 |
34 | Item removeFromFront();
35 | Item removeFromBack();
36 | Item remove ( unsigned i );
37 |
38 | DDCRET insert ( unsigned index, const Item &x ) // make new item at index
39 | {
40 | Item *newX = new Item(x);
41 | return vpList.insert ( index, newX );
42 | }
43 |
44 | DDCRET addToFront ( const Item &x ) {return insert ( 0, x );}
45 | DDCRET addToBack ( const Item &x ) {return insert ( numItems(), x );}
46 |
47 | private:
48 | Impl vpList; // an implementation of a list of (void *)
49 | };
50 |
51 |
52 | template
53 | List- ::~List()
54 | {
55 | reset();
56 | }
57 |
58 |
59 | template
60 | void List
- ::reset()
61 | {
62 | unsigned n = vpList.numItems();
63 |
64 | while ( n-- > 0 )
65 | {
66 | Item *x = (Item *) ( vpList.remove(0) );
67 | delete x;
68 | }
69 | }
70 |
71 |
72 | template
73 | Item List
- ::removeFromFront()
74 | {
75 | Item *xPtr = (Item *) ( vpList.remove(0) );
76 | Item x = *xPtr;
77 | delete xPtr;
78 | return x;
79 | }
80 |
81 |
82 | template
83 | Item List
- ::removeFromBack()
84 | {
85 | Item *xPtr = (Item *) ( vpList.remove ( vpList.numItems() - 1 ) );
86 | Item x = *xPtr;
87 | delete xPtr;
88 | return x;
89 | }
90 |
91 |
92 | template
93 | Item List
- ::remove ( unsigned index )
94 | {
95 | Item *xPtr = (Item *) ( vpList.remove ( index ) );
96 | Item x = *xPtr;
97 | delete xPtr;
98 | return x;
99 | }
100 |
101 |
102 | template
103 | class LList: public List
-
104 | {
105 | public:
106 | LList() {}
107 | ~LList() {}
108 |
109 | private:
110 | };
111 |
112 |
113 | class LinkedImplementation
114 | {
115 | public:
116 | LinkedImplementation();
117 | ~LinkedImplementation();
118 |
119 | unsigned numItems() const {return numItemsInList;}
120 | void * operator [] ( unsigned index ) const;
121 |
122 | DDCRET insert ( unsigned index, void *newItem );
123 | void *remove ( unsigned index );
124 |
125 | private:
126 |
127 | struct node
128 | {
129 | node *next;
130 | node *prev;
131 | void *item;
132 |
133 | node ( void *initItem, node *initNext=0, node *initPrev=0 ):
134 | next(initNext), prev(initPrev), item(initItem) {}
135 | };
136 |
137 | node *seek ( unsigned newCurrentIndex );
138 |
139 | unsigned numItemsInList;
140 | node *front;
141 | node *back;
142 | node *current;
143 | unsigned currentIndex;
144 | };
145 |
146 |
147 | #endif // __DDC_CONTAIN_H
148 |
149 | /*--- end of file contain.h ---*/
150 |
--------------------------------------------------------------------------------
/openbook/ddc.h:
--------------------------------------------------------------------------------
1 | /*============================================================================
2 |
3 | ddc.h - Don Cross, October 1992.
4 |
5 | Generic ddclib stuff.
6 |
7 | ============================================================================*/
8 |
9 | #ifndef __DDC_DDC_H
10 | #define __DDC_DDC_H
11 |
12 | // If you add something to DDCRET, please add the appropriate string
13 | // to the function DDCRET_String() in the file 'source\ddcret.cpp'.
14 |
15 | enum DDCRET
16 | {
17 | DDC_SUCCESS, // The operation succeded
18 | DDC_FAILURE, // The operation failed for unspecified reasons
19 | DDC_OUT_OF_MEMORY, // Operation failed due to running out of memory
20 | DDC_FILE_ERROR, // Operation encountered file I/O error
21 | DDC_INVALID_CALL, // Operation was called with invalid parameters
22 | DDC_USER_ABORT, // Operation was aborted by the user
23 | DDC_INVALID_FILE // File format does not match
24 | };
25 |
26 |
27 | const char *DDCRET_String ( DDCRET ); // See source\ddcret.cpp
28 |
29 |
30 | #define TRUE 1
31 | #define FALSE 0
32 |
33 | typedef int dBOOLEAN;
34 |
35 | typedef unsigned char BYTE;
36 |
37 | typedef unsigned char UINT8;
38 | typedef signed char INT8;
39 |
40 | typedef unsigned short int UINT16;
41 | typedef signed short int INT16;
42 | typedef unsigned long int UINT32;
43 | typedef signed long int INT32;
44 |
45 | #ifdef __BORLANDC__
46 | #if sizeof(UINT16) != 2
47 | #error Need to fix UINT16 and INT16
48 | #endif
49 |
50 | #if sizeof(UINT32) != 4
51 | #error Need to fix UINT32 and INT32
52 | #endif
53 | #endif
54 |
55 | #endif /* __DDC_DDC_H */
56 |
57 | /*--- end of file ddc.h ---*/
58 |
--------------------------------------------------------------------------------
/openbook/limp.cpp:
--------------------------------------------------------------------------------
1 | /*==========================================================================
2 |
3 | limp.cpp - Don Cross, September 1993.
4 |
5 | Contains class LinkedImplementation.
6 | This is a helper class for the List<> class template.
7 | Together, they can make an LList<>.
8 |
9 | ==========================================================================*/
10 |
11 | // Standard includes
12 | #include
13 | #include
14 |
15 | using namespace std;
16 |
17 | // DDCLIB includes
18 | #include "contain.h"
19 |
20 |
21 | LinkedImplementation::LinkedImplementation():
22 | numItemsInList ( 0 ),
23 | front ( 0 ),
24 | back ( 0 ),
25 | current ( 0 ),
26 | currentIndex ( 0 )
27 | {
28 | }
29 |
30 |
31 | LinkedImplementation::~LinkedImplementation()
32 | {
33 | if ( numItemsInList > 0 )
34 | {
35 | // This is a fatal error because class LinkedImplementation
36 | // does not know how to destroy the items it contains.
37 | // (It knows of them only via void pointers).
38 |
39 | cerr << "Fatal error in LinkedImplementation::~LinkedImplementation():" << endl;
40 | cerr << "List was not cleaned up by user before deletion!" << endl;
41 | exit(1);
42 | }
43 | }
44 |
45 |
46 | void *LinkedImplementation::operator[] ( unsigned index ) const
47 | {
48 | LinkedImplementation *me = (LinkedImplementation *) this;
49 | node *x = me->seek(index);
50 | if ( !x )
51 | {
52 | cerr << "Fatal error in LinkedImplementation::operator[]" << endl;
53 | cerr << "me->seek returned NULL" << endl << endl;
54 | exit(1);
55 | }
56 |
57 | if ( !(x->item) )
58 | {
59 | cerr << "Fatal error in LinkedImplementation::operator[]" << endl;
60 | cerr << "x != NULL but x->item == NULL" << endl;
61 | }
62 |
63 | return x->item;
64 | }
65 |
66 |
67 | LinkedImplementation::node *LinkedImplementation::seek ( unsigned index )
68 | {
69 | if ( index >= numItemsInList )
70 | {
71 | cerr << "Fatal error in LinkedImplementation::seek(" <<
72 | index << "): subscript out of range!" << endl;
73 |
74 | exit(1);
75 | }
76 |
77 | if ( !current )
78 | {
79 | // If we get here, it means that we need to reset our "indexing cache"
80 |
81 | current = front;
82 | currentIndex = 0;
83 | }
84 |
85 | // Seek forward if necessary...
86 | while ( currentIndex < index )
87 | {
88 | ++currentIndex;
89 | current = current->next;
90 | }
91 |
92 | // Seek backward if necessary...
93 | while ( currentIndex > index )
94 | {
95 | --currentIndex;
96 | current = current->prev;
97 | }
98 |
99 | return current;
100 | }
101 |
102 |
103 | DDCRET LinkedImplementation::insert ( unsigned index, void *newItem )
104 | {
105 | if ( !newItem )
106 | {
107 | cerr << "Fatal error in LinkedImplementation::insert()" << endl;
108 | cerr << "newItem == NULL" << endl << endl;
109 | exit(1);
110 | }
111 |
112 | node *newNode = new node ( newItem );
113 |
114 | if ( !newNode )
115 | {
116 | return DDC_OUT_OF_MEMORY;
117 | }
118 |
119 | if ( index == 0 )
120 | {
121 | // prepend to list...
122 |
123 | newNode->next = front;
124 | if ( front )
125 | {
126 | front = front->prev = newNode;
127 | }
128 | else
129 | {
130 | front = back = newNode;
131 | }
132 | }
133 | else if ( index == numItemsInList )
134 | {
135 | // append to list...
136 |
137 | newNode->prev = back;
138 | if ( back )
139 | {
140 | back = back->next = newNode;
141 | }
142 | else
143 | {
144 | back = newNode;
145 | }
146 | }
147 | else
148 | {
149 | // It goes somewhere in the middle...
150 |
151 | seek(index);
152 |
153 | newNode->next = current;
154 | newNode->prev = current->prev;
155 | current->prev = newNode->prev->next = newNode;
156 | }
157 |
158 | current = newNode;
159 | currentIndex = index;
160 | ++numItemsInList;
161 |
162 | return DDC_SUCCESS;
163 | }
164 |
165 |
166 | void *LinkedImplementation::remove ( unsigned index )
167 | {
168 | void *itemPointer = seek(index)->item;
169 |
170 | if ( current->prev )
171 | {
172 | current->prev->next = current->next;
173 | }
174 | else
175 | {
176 | front = current->next;
177 | }
178 |
179 | if ( current->next )
180 | {
181 | current->next->prev = current->prev;
182 | }
183 | else
184 | {
185 | back = current->prev;
186 | }
187 |
188 | --numItemsInList;
189 | delete current;
190 | current = 0;
191 | return itemPointer;
192 | }
193 |
194 |
195 | /*--- end of file limp.cpp ---*/
196 |
--------------------------------------------------------------------------------
/openbook/obt.bat:
--------------------------------------------------------------------------------
1 | if exist openbook.cpp (del openbook.cpp)
2 | debug\obt.exe
3 | copy openbook.cpp ..\src\openbook.cpp
4 |
--------------------------------------------------------------------------------
/openbook/openbook.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 |
--------------------------------------------------------------------------------
/portable/portable.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files
56 |
57 |
58 | Source Files
59 |
60 |
61 | Source Files
62 |
63 |
64 | Source Files
65 |
66 |
67 | Source Files
68 |
69 |
70 | Source Files
71 |
72 |
73 | Source Files
74 |
75 |
76 | Source Files
77 |
78 |
79 | Source Files
80 |
81 |
82 | Source Files
83 |
84 |
85 | Source Files
86 |
87 |
88 | Source Files
89 |
90 |
91 | Source Files
92 |
93 |
94 | Source Files
95 |
96 |
97 | Source Files
98 |
99 |
100 | Source Files
101 |
102 |
103 | Source Files
104 |
105 |
106 | Source Files
107 |
108 |
109 | Source Files
110 |
111 |
112 | Source Files
113 |
114 |
115 | Source Files
116 |
117 |
118 | Source Files
119 |
120 |
121 |
122 |
123 | Header Files
124 |
125 |
126 | Header Files
127 |
128 |
129 | Header Files
130 |
131 |
132 | Header Files
133 |
134 |
135 | Header Files
136 |
137 |
138 | Header Files
139 |
140 |
141 | Header Files
142 |
143 |
144 |
--------------------------------------------------------------------------------
/res/chenard1.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cosinekitty/chenard/6dd9b07110ac9b7f5d7be1a3e667b56120ddbcb1/res/chenard1.ico
--------------------------------------------------------------------------------
/res/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Developer Studio generated include file.
3 | // Used by winchen.rc
4 | //
5 | #define IDB_BB 103
6 | #define IDB_BK 104
7 | #define IDB_BN 105
8 | #define IDB_BP 106
9 | #define IDB_BQ 107
10 | #define IDB_BR 108
11 | #define IDB_WB 109
12 | #define IDB_WK 110
13 | #define IDB_WN 111
14 | #define IDB_WP 112
15 | #define IDB_WQ 113
16 | #define IDB_WR 114
17 | #define TB_W_PIPE_NAME 1002
18 | #define TB_B_PIPE_NAME 1003
19 | #define IDC_CHECK_BLUNDER_ALERT_WHITE 1004
20 | #define IDC_CHECK_BLUNDER_ALERT_BLACK 1005
21 | #define IDC_EDIT_EMPTY 1012
22 | #define IDC_EDIT_WHITE 1013
23 | #define IDC_EDIT_BLACK 1014
24 | #define IDC_EDIT_PAWN 1015
25 | #define IDC_EDIT_KNIGHT 1016
26 | #define IDC_EDIT_BISHOP 1017
27 | #define IDC_EDIT_ROOK 1018
28 | #define IDC_EDIT_QUEEN 1019
29 | #define IDC_EDIT_KING 1020
30 | #define IDC_EDIT_WHITE_TIME 1021
31 | #define IDC_EDIT_BLACK_TIME 1022
32 | #define IDC_CHESS_CLIENT 1027
33 | #define IDC_REMOTE_IP 1028
34 | #define IDC_EDIT_SUGGEST_TIME 1029
35 | #define IDC_CHECK_DING_AFTER_SUGGEST 1030
36 | #define IDC_EDIT_BLUNDER_THRESHOLD 1031
37 | #define ID_GAME_OPPTIME 40001
38 | #define ID_CHENARD_FILE_EXIT 40002
39 | #define ID_EDIT_CLEARBOARD 40003
40 | #define ID_EDIT_EDITMODE 40004
41 | #define ID_VIEW_ROTATEBOARD 40005
42 | #define ID_VIEW_DEBUGINFO 40007
43 | #define ID_HELP_ABOUT 40008
44 | #define ID_GAME_FORCEMOVE 40009
45 | #define ID_EDIT_COPYGAMELISTING 40013
46 | #define ID_CHENARD_FILE_SAVEAS 40016
47 | #define ID_GAME_TACTICALBENCHMARK 40023
48 | #define ID_EDIT_THINK_TIMES 40024
49 | #define ID_EDIT_UNDOMOVE 40026
50 | #define ID_EDIT_REDOMOVE 40027
51 | #define ID_VIEW_SPEAKMOVESTHROUGHSOUNDCARD 40029
52 | #define ID_HELP_VISITCHENARDWEBPAGE 40030
53 | #define ID_VIEW_ANALYSIS_NONE 40031
54 | #define ID_VIEW_ANALYSIS_BESTPATH 40032
55 | #define ID_VIEW_ANALYSIS_CURRENTPATH 40033
56 | #define ID_GAME_ALLOWCOMPUTERTORESIGN 40034
57 | #define ID_GAME_RESIGN 40035
58 | #define ID_HIGHLIGHT_MOVE 40036
59 | #define ID_ANIMATE 40037
60 | #define ID_GAME_AUTO_SINGULAR 40038
61 | #define ID_GAME_ALLOWEXTENDEDSEARCH 40039
62 | #define ID_DUMP_XPOS_TABLE 40040
63 | #define ID_GAME_SUGGEST 40041
64 | #define ID_HELP_HOWDOICASTLE 40042
65 | #define ID_CHENARD_FILE_NEW 41000
66 | #define ID_CHENARD_FILE_OPEN 41001
67 | #define ID_CHENARD_FILE_SAVE 41002
68 | #define ID_KEY_N 42002
69 | #define ID_KEY_S 42003
70 | #define ID_KEY_E 42004
71 | #define ID_KEY_W 42005
72 | #define ID_KEY_NW 42006
73 | #define ID_KEY_SW 42007
74 | #define ID_KEY_NE 42008
75 | #define ID_KEY_SE 42009
76 | #define ID_KEY_CHOOSE 42010
77 | #define ID_VIEW_ANNOUNCEMATE 42011
78 | #define ID_EDIT_COPY_FEN 42012
79 | #define ID_ENTER_FEN 42013
80 | #define ID_ALGEBRAIC_A 42014
81 | #define ID_ALGEBRAIC_B 42015
82 | #define ID_ALGEBRAIC_C 42016
83 | #define ID_ALGEBRAIC_D 42017
84 | #define ID_ALGEBRAIC_E 42018
85 | #define ID_ALGEBRAIC_F 42019
86 | #define ID_ALGEBRAIC_G 42020
87 | #define ID_ALGEBRAIC_H 42021
88 | #define ID_ALGEBRAIC_1 42022
89 | #define ID_ALGEBRAIC_2 42023
90 | #define ID_ALGEBRAIC_3 42024
91 | #define ID_ALGEBRAIC_4 42025
92 | #define ID_ALGEBRAIC_5 42026
93 | #define ID_ALGEBRAIC_6 42027
94 | #define ID_ALGEBRAIC_7 42028
95 | #define ID_ALGEBRAIC_8 42029
96 | #define ID_GAME_SUGGESTAGAIN 42030
97 | #define ID_EDIT_BLUNDER_THRESHOLD 42031
98 |
99 | // Next default values for new objects
100 | //
101 | #ifdef APSTUDIO_INVOKED
102 | #ifndef APSTUDIO_READONLY_SYMBOLS
103 | #define _APS_NEXT_RESOURCE_VALUE 181
104 | #define _APS_NEXT_COMMAND_VALUE 42032
105 | #define _APS_NEXT_CONTROL_VALUE 1032
106 | #define _APS_NEXT_SYMED_VALUE 101
107 | #endif
108 | #endif
109 |
--------------------------------------------------------------------------------
/src/chenga.h:
--------------------------------------------------------------------------------
1 | /*=============================================================================
2 |
3 | chenga.h - Copyright (C) 1999-2005 by Don Cross
4 |
5 | This header file contains definitions for a genetic algorithm
6 | for evolving move ordering and eval heuristics.
7 |
8 | =============================================================================*/
9 | #ifndef __ddc_chenard_chenga_h
10 | #define __ddc_chenard_chenga_h 1
11 |
12 |
13 | struct ChessGeneInfo
14 | {
15 | ChessGene gene;
16 | long numWins;
17 | long numLosses;
18 | long numDraws;
19 | long numGamesAsWhite;
20 | long numGamesAsBlack;
21 | long id;
22 |
23 | double fitness() const;
24 | long numGames() const { return numGamesAsWhite + numGamesAsBlack; }
25 |
26 | ChessGeneInfo():
27 | numWins(0),
28 | numLosses(0),
29 | numDraws(0),
30 | numGamesAsWhite(0),
31 | numGamesAsBlack(0),
32 | id(0)
33 | {}
34 | };
35 |
36 |
37 | class ChessGA
38 | {
39 | public:
40 | ChessGA ( ChessUI &, int _allowTextOutput );
41 | ~ChessGA();
42 |
43 | void createRandomPopulation ( int _numGenes );
44 | int save();
45 | int saveGenFiles(); // saves state to files in current directory
46 | int saveGaOnly(); // save ga file, but not gen files
47 | int load ( const char *dirPrefix = "" );
48 | void run();
49 |
50 | static int MergePools (
51 | int outputPoolSize,
52 | int dirc,
53 | const char *dirv[],
54 | ChessUI &,
55 | int _allowTextOutput );
56 |
57 | protected:
58 | ChessGA();
59 |
60 | // The following function competes two genes (specified by their indices)
61 | // against each other. The function returns 1 if the first gene wins the game,
62 | // -1 if the second gene wins, and 0 if there is a draw.
63 | int battle ( int g1, int g2 );
64 |
65 | // The following function is called when the GA decides enough games
66 | // have been played to kill stupid genes and breed smart ones.
67 | void grimReaper();
68 |
69 | void sortGenes(); // sort in descending order of fitness
70 |
71 | void loadGene ( ComputerChessPlayer &, int geneIndex, INT32 thinkTime );
72 |
73 | int printf ( const char *format, ... ); // prints to stdout if allowTextOutput nonzero
74 | int lprintf ( const char *format, ... ); // appends to log file
75 | void logdate ( const char *description ); // appends current date and time to log file
76 |
77 | bool isSpecialDraw ( const ChessBoard & );
78 |
79 | void displayGameResults ( const char *message );
80 |
81 | private:
82 | int allowTextOutput;
83 | ChessUI *ui;
84 | int numGenes; // fixed population size
85 | ChessGeneInfo *info;
86 | int currentGene; // index of next gene to be exercised
87 | long numRounds; // total cycles through gene pool completed
88 | long numGamesCompleted;
89 | INT32 startTime;
90 | long nextGeneId;
91 |
92 | long numWhiteWins;
93 | long numBlackWins;
94 | long numDraws;
95 |
96 | SCORE resignThreshold;
97 | INT32 minTime;
98 | INT32 spreadTime;
99 |
100 | // The following are used by ChessGA::battle() to detect special draws.
101 | int rooksAndKingsPlies; // number of plies board has had only R+K vs R+K
102 | };
103 |
104 |
105 | int GeneBattle (
106 | ChessUI &,
107 | const char *geneFilename1,
108 | const char *geneFilename2 );
109 |
110 |
111 | #endif // __ddc_chenard_chenga_h
112 |
113 | /*
114 | $Log: chenga.h,v $
115 | Revision 1.4 2006/01/18 19:58:11 dcross
116 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
117 | Now use C++ standard bool, true, false (none of which existed when I started this project).
118 |
119 | Revision 1.3 2005/11/23 21:30:29 dcross
120 | Removed all references to intersrv.com, because that ISP no longer exists!
121 | Changed references to Chenard web site and my email address to cosinekitty.com.
122 | (Still need to fix cosinekitty.com/chenard.html.)
123 |
124 | Revision 1.2 2005/11/23 21:14:38 dcross
125 | 1. Added cvs log tag at end of each source file.
126 | 2. Moved old manual revision history after cvs log tag.
127 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
128 |
129 |
130 | Revision history:
131 |
132 | 1999 February 18 [Don Cross]
133 | Started writing.
134 |
135 | */
136 |
137 |
--------------------------------------------------------------------------------
/src/convert.cpp:
--------------------------------------------------------------------------------
1 | // convert.cpp - main() for converting old tree to new tree.
2 |
3 | #include
4 | #include
5 |
6 | #include "chess.h"
7 | #include "lrntree.h"
8 |
9 | int main ()
10 | {
11 | // Load the old learning tree
12 |
13 | Learn_Output = 1;
14 | printf ( "Loading old learning tree...\n" );
15 | LoadLearningTree();
16 | printf ( "Beginning conversion...\n" );
17 | ConvertLearningTree ( DEFAULT_CHENARD_TREE_FILENAME );
18 | printf ( "Conversion finished!\n" );
19 |
20 | return 0;
21 | }
22 |
23 |
24 | void ChessFatal ( const char *message )
25 | {
26 | fprintf ( stderr, message );
27 | exit(1);
28 | }
29 |
30 | /*
31 | $Log: convert.cpp,v $
32 | Revision 1.2 2006/03/20 20:44:10 dcross
33 | I finally figured out the weird slowness I have been seeing in Chenard accessing
34 | its experience tree. It turns out it only happens the first time it accessed the file
35 | chenard.tre after a reboot. It was caused by Windows XP thinking chenard.tre was
36 | an important system file, because of its extension:
37 | http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sr/sr/monitored_file_extensions.asp
38 | We write 36 bytes to the middle of the file, then close it
39 | So I have changed the filename from chenard.tre to chenard.trx.
40 | I also added DEFAULT_CHENARD_TREE_FILENAME in lrntree.h so that I can more
41 | easily rename this again if need be.
42 |
43 | Revision 1.1 2005/11/25 19:47:26 dcross
44 | Recovered lots of old chess source files from the dead!
45 | Found these on CDROM marked "14 September 1999".
46 | Added cvs log tag and moved old revision history after that.
47 |
48 | */
49 |
50 |
--------------------------------------------------------------------------------
/src/crand.cpp:
--------------------------------------------------------------------------------
1 | /*==========================================================================
2 |
3 | crand.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | Contains random number generator for chess.
6 |
7 | ==========================================================================*/
8 |
9 | #include
10 | #include
11 | #include "chess.h"
12 |
13 |
14 | #define MULTIPLIER 0x015a4e35L
15 | #define INCREMENT 1
16 |
17 | static INT32 Seed = 1;
18 |
19 |
20 | static INT16 _ChessRandom ()
21 | {
22 | Seed = MULTIPLIER * Seed + INCREMENT;
23 | INT16 r = INT16(Seed >> 16) & 0x7fff;
24 | if (r < 0)
25 | {
26 | ChessFatal ("Negative value returned by _ChessRandom");
27 | }
28 | return r;
29 | }
30 |
31 |
32 | int ChessRandom ( int n )
33 | {
34 | static int firstTime = 1;
35 | if ( firstTime )
36 | {
37 | firstTime = 0;
38 | Seed = INT32 ( time(NULL) );
39 | }
40 |
41 | if ( n <= 0 )
42 | {
43 | ChessFatal ( "Non-positive argument to ChessRandom()!" );
44 | return 0;
45 | }
46 |
47 | int r = int(_ChessRandom()) % n;
48 | if (r<0 || r>=n)
49 | {
50 | ChessFatal ("ChessRandom is broken!");
51 | }
52 | return r;
53 | }
54 |
55 |
56 | /*
57 | $Log: crand.cpp,v $
58 | Revision 1.4 2006/03/19 20:27:12 dcross
59 | Still trying to find bug that causes Chenard to occasionally delay a long time when first using experience tree.
60 | All I have found so far is what looked like a negative number being returned by ChessRandom,
61 | but I cannot reproduce it. So I just stuck in ChessFatal calls to see if it ever happens again.
62 | Also found a case where we open the experience tree twice by creating a redundant LearnTree object.
63 | I removed the unnecessary redundancy, thinking maybe trying to open the file twice is causing some
64 | kind of delay. So far this is just shooting in the dark!
65 |
66 | Revision 1.3 2005/11/23 21:30:29 dcross
67 | Removed all references to intersrv.com, because that ISP no longer exists!
68 | Changed references to Chenard web site and my email address to cosinekitty.com.
69 | (Still need to fix cosinekitty.com/chenard.html.)
70 |
71 | Revision 1.2 2005/11/23 21:14:38 dcross
72 | 1. Added cvs log tag at end of each source file.
73 | 2. Moved old manual revision history after cvs log tag.
74 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
75 |
76 |
77 | Revision history:
78 |
79 | 1999 February 14 [Don Cross]
80 | Added code to call ChessFatal() if argument to ChessRandom()
81 | is non-positive.
82 | Changing time-based seed initializer from global variable's
83 | constructor to first time flag.
84 |
85 | */
86 |
87 |
--------------------------------------------------------------------------------
/src/dispgame.cpp:
--------------------------------------------------------------------------------
1 | /*===========================================================================
2 |
3 | dispgame.cpp - Copyright (C) 1993-1998 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | Utility to dump a NewChess CHESS.GAM file to stdout.
8 |
9 | ===========================================================================*/
10 |
11 | #include
12 | #include
13 | #include "chess.h"
14 |
15 | int main ( int argc, char *argv[] )
16 | {
17 | if ( argc < 2 || argc > 3 )
18 | {
19 | fprintf ( stderr, "Use: DISPGAME game_in_file [text_out_file]\n" );
20 | return 1;
21 | }
22 |
23 | const char *infilename = argv[1];
24 |
25 | FILE *infile = fopen ( argv[1], "rb" );
26 |
27 | if ( !infile )
28 | {
29 | fprintf ( stderr, "Error: Cannot open input file '%s'\n", infilename );
30 | return 1;
31 | }
32 |
33 | FILE *outfile = stdout;
34 |
35 | if ( argc == 3 )
36 | {
37 | outfile = fopen ( argv[2], "wt" );
38 | if ( !outfile )
39 | {
40 | fprintf ( stderr, "Error: Cannot open output file '%s'\n", argv[2] );
41 | fclose(infile);
42 | return 1;
43 | }
44 | }
45 |
46 | ChessBoard board;
47 | Move move;
48 | UnmoveInfo unmove;
49 | int movenum = 1;
50 | char moveString [MAX_MOVE_STRLEN + 1];
51 |
52 | fprintf ( outfile, " %-15s %-15s\n\n", "White", "Black" );
53 |
54 | while ( fread ( &move, sizeof(Move), 1, infile ) == 1 )
55 | {
56 | FormatChessMove ( board, move, moveString );
57 |
58 | if ( board.WhiteToMove() )
59 | {
60 | fprintf ( outfile, "%3d. %-15s", movenum, moveString );
61 | board.MakeWhiteMove ( move, unmove, true, true );
62 | }
63 | else
64 | {
65 | fprintf ( outfile, " %-15s\n", moveString );
66 | board.MakeBlackMove ( move, unmove, true, true );
67 | ++movenum;
68 | }
69 | }
70 |
71 | fprintf ( outfile, "\n" );
72 |
73 | fclose ( infile );
74 |
75 | if ( argc != 3 )
76 | {
77 | fclose ( outfile );
78 | }
79 |
80 | return 0;
81 | }
82 |
83 |
84 | void ChessFatal ( const char *message )
85 | {
86 | fprintf ( stderr, "Fatal chess error: %s\n", message );
87 | exit(1);
88 | }
89 |
90 |
91 | /*
92 | $Log: dispgame.cpp,v $
93 | Revision 1.2 2006/01/18 19:58:11 dcross
94 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
95 | Now use C++ standard bool, true, false (none of which existed when I started this project).
96 |
97 | Revision 1.1 2005/11/25 19:47:26 dcross
98 | Recovered lots of old chess source files from the dead!
99 | Found these on CDROM marked "14 September 1999".
100 | Added cvs log tag and moved old revision history after that.
101 |
102 | */
103 |
104 |
--------------------------------------------------------------------------------
/src/dumptree.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "chess.h"
4 | #include "lrntree.h"
5 |
6 | int main ( int argc, char *argv[] )
7 | {
8 | const char *treeFilename = DEFAULT_CHENARD_TREE_FILENAME;
9 | if ( argc > 1 )
10 | treeFilename = argv[1];
11 |
12 | LearnTree tree;
13 | if ( !tree.open(treeFilename) )
14 | {
15 | cerr << "Cannot open input file '" << treeFilename << "'" << endl;
16 | return 1;
17 | }
18 |
19 | cout << "Successfully opened input file '" << treeFilename << "'" << endl;
20 |
21 | const char *listFilename = "dumptree.txt";
22 | FILE *f = fopen (listFilename, "wt");
23 | if ( !f )
24 | {
25 | cerr << "Cannot open output list file '" << listFilename << "'" << endl;
26 | return 1;
27 | }
28 |
29 | LearnBranch branch;
30 | for ( INT32 offset=0; tree.read(offset,branch); offset++ )
31 | {
32 | fprintf ( f,
33 | "%10ld: m=[%3u,%3u,%6d] t=%-6.2lf wl=%-3ld c=%-9ld s=%-9ld\n",
34 | long (offset),
35 | unsigned (branch.move.source),
36 | unsigned (branch.move.dest),
37 | int (branch.move.score),
38 | double (branch.timeAnalyzed / 100.0),
39 | long (branch.winsAndLosses),
40 | long (branch.child),
41 | long (branch.sibling) );
42 | }
43 |
44 | fclose (f);
45 | tree.close();
46 |
47 | return 0;
48 | }
49 |
50 | /*
51 | $Log: dumptree.cpp,v $
52 | Revision 1.2 2006/03/20 20:44:10 dcross
53 | I finally figured out the weird slowness I have been seeing in Chenard accessing
54 | its experience tree. It turns out it only happens the first time it accessed the file
55 | chenard.tre after a reboot. It was caused by Windows XP thinking chenard.tre was
56 | an important system file, because of its extension:
57 | http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sr/sr/monitored_file_extensions.asp
58 | We write 36 bytes to the middle of the file, then close it
59 | So I have changed the filename from chenard.tre to chenard.trx.
60 | I also added DEFAULT_CHENARD_TREE_FILENAME in lrntree.h so that I can more
61 | easily rename this again if need be.
62 |
63 | Revision 1.1 2005/11/25 19:47:27 dcross
64 | Recovered lots of old chess source files from the dead!
65 | Found these on CDROM marked "14 September 1999".
66 | Added cvs log tag and moved old revision history after that.
67 |
68 | */
69 |
70 |
--------------------------------------------------------------------------------
/src/endgame.cpp:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | endgame.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | Knows how to play certain endgame positions better
6 | than the min-max search does.
7 | Its opinion (when it offers one) will supersede
8 | doing a search.
9 |
10 | =======================================================================*/
11 |
12 | #include "chess.h"
13 | #include "profiler.h"
14 |
15 | int Distance2 ( int ofs1, int ofs2 )
16 | {
17 | int dx = XPART(ofs1) - XPART(ofs2);
18 | int dy = YPART(ofs1) - YPART(ofs2);
19 | return dx*dx + dy*dy;
20 | }
21 |
22 |
23 | //--------------------------------------------------------------------------
24 |
25 | // If will checkmate with queen or rook, force king toward any corner.
26 | const int ComputerChessPlayer::KingPosTableQR [144] =
27 | {
28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
30 |
31 | 0, 0, 100, 90, 70, 50, 50, 70, 90, 100, 0, 0,
32 | 0, 0, 90, 70, 35, 20, 20, 35, 70, 90, 0, 0,
33 | 0, 0, 70, 35, 15, 10, 10, 15, 35, 70, 0, 0,
34 | 0, 0, 50, 20, 10, 0, 0, 10, 20, 50, 0, 0,
35 | 0, 0, 50, 20, 10, 0, 0, 10, 20, 50, 0, 0,
36 | 0, 0, 70, 35, 15, 10, 10, 15, 35, 70, 0, 0,
37 | 0, 0, 90, 70, 35, 20, 20, 35, 70, 90, 0, 0,
38 | 0, 0, 100, 90, 70, 50, 50, 70, 90, 100
39 | };
40 |
41 |
42 | // If will checkmate with bishop on white, force toward white corner
43 | const int ComputerChessPlayer::KingPosTableBW [144] =
44 | {
45 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 |
48 | 0, 0, -100, -90, -70, -50, 50, 70, 90, 100, 0, 0,
49 | 0, 0, -90, -70, -35, -20, 20, 35, 70, 90, 0, 0,
50 | 0, 0, -70, -35, -15, -10, 10, 15, 35, 70, 0, 0,
51 | 0, 0, -50, -20, -10, -5, 0, 10, 20, 50, 0, 0,
52 | 0, 0, 50, 20, 10, 0, -5, -10, -20, -50, 0, 0,
53 | 0, 0, 70, 35, 15, 10, -10, -15, -35, -70, 0, 0,
54 | 0, 0, 90, 70, 35, 20, -20, -35, -70, -90, 0, 0,
55 | 0, 0, 100, 90, 70, 50, -50, -70, -90,-100
56 | };
57 |
58 |
59 | // If will checkmate with bishop on black, force toward black corner
60 | const int ComputerChessPlayer::KingPosTableBB [144] =
61 | {
62 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 |
65 | 0, 0, 100, 90, 70, 50, -50, -70, -90,-100, 0, 0,
66 | 0, 0, 90, 70, 35, 20, -20, -35, -70, -90, 0, 0,
67 | 0, 0, 70, 35, 15, 10, -10, -15, -35, -70, 0, 0,
68 | 0, 0, 50, 20, 10, 0, -5, -10, -20, -50, 0, 0,
69 | 0, 0, -50, -20, -10, -5, 0, 10, 20, 50, 0, 0,
70 | 0, 0, -70, -35, -15, -10, 10, 15, 35, 70, 0, 0,
71 | 0, 0, -90, -70, -35, -20, 20, 35, 70, 90, 0, 0,
72 | 0, 0, -100, -90, -70, -50, 50, 70, 90, 100
73 | };
74 |
75 |
76 | SCORE ComputerChessPlayer::EndgameEval1 (
77 | ChessBoard &board,
78 | int depth,
79 | SCORE, SCORE )
80 | {
81 | PROFILER_ENTER(PX_EVAL);
82 | ++evaluated;
83 |
84 | // Look for definite draw...
85 | if ( board.IsDefiniteDraw() )
86 | return DRAW;
87 |
88 | // Look for stalemates and checkmates...
89 | if ( board.white_to_move )
90 | {
91 | if ( !board.WhiteCanMove() )
92 | {
93 | if ( board.flags & SF_WCHECK )
94 | return BLACK_WINS + WIN_POSTPONEMENT(depth); // White has been checkmated
95 | else
96 | return DRAW; // White has been stalemated
97 | }
98 | }
99 | else // It's Black's turn to move
100 | {
101 | if ( !board.BlackCanMove() )
102 | {
103 | if ( board.flags & SF_BCHECK )
104 | return WHITE_WINS - WIN_POSTPONEMENT(depth); // Black has been checkmated
105 | else
106 | return DRAW; // Black has been stalemated
107 | }
108 | }
109 |
110 | // If we are using this eval, exactly one side had a lone king
111 | // at the root of the search tree. Figure out which side that
112 | // is by looking at material balance.
113 |
114 | SCORE score = MaterialEval ( board.wmaterial, board.bmaterial );
115 | int kdist = Distance2 ( board.wk_offset, board.bk_offset );
116 | if ( score < 0 )
117 | {
118 | // Black is winning...see how bad off White's lone king is now...
119 | score += (kdist - 10000 - KingPosTable[board.wk_offset]);
120 | score -= ProximityBonus ( board, board.wk_offset, BR_MASK|BQ_MASK|BN_MASK|BB_MASK );
121 | }
122 | else
123 | {
124 | // White is winning...see how bad off Black's lone king is now...
125 | score -= (kdist - 10000 - KingPosTable[board.bk_offset]);
126 | score += ProximityBonus ( board, board.bk_offset, WR_MASK|WQ_MASK|WN_MASK|WB_MASK );
127 | }
128 |
129 | PROFILER_EXIT()
130 |
131 | return score;
132 | }
133 |
134 |
135 | SCORE ComputerChessPlayer::ProximityBonus (
136 | ChessBoard &board,
137 | int target_ofs,
138 | int mask )
139 | {
140 | SCORE bonus = 0;
141 |
142 | for ( int y=OFFSET(2,2); y <= OFFSET(2,9); y += NORTH )
143 | for ( int x=0; x < 8; ++x )
144 | if ( board.board[x+y] & mask )
145 | {
146 | SCORE delta = Distance2 ( x + y, target_ofs );
147 | if ( !(board.board[x+y] & (BR_MASK|WR_MASK|BQ_MASK|WQ_MASK)) )
148 | delta /= 12;
149 | bonus -= delta;
150 | }
151 |
152 | return bonus / 4;
153 | }
154 |
155 |
156 |
157 | /*
158 | $Log: endgame.cpp,v $
159 | Revision 1.3 2005/11/23 21:30:29 dcross
160 | Removed all references to intersrv.com, because that ISP no longer exists!
161 | Changed references to Chenard web site and my email address to cosinekitty.com.
162 | (Still need to fix cosinekitty.com/chenard.html.)
163 |
164 | Revision 1.2 2005/11/23 21:14:38 dcross
165 | 1. Added cvs log tag at end of each source file.
166 | 2. Moved old manual revision history after cvs log tag.
167 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
168 |
169 |
170 |
171 | Revision History:
172 |
173 | 1994 January 19 [Don Cross]
174 | Started adding real endgame algorithms!
175 |
176 | 1994 January 22 [Don Cross]
177 | I have decided to try something different, and abandon
178 | the Chester-esque use of special endgame heuristics.
179 | Instead, I am going to adapt these heuristics into
180 | a special eval function, and use the normal search code.
181 | Before starting a search, the ComputerChessPlayer object
182 | will determine which evaluation function is appropriate
183 | and use it throughout the search.
184 |
185 | 1994 January 25 [Don Cross]
186 | Adding small bonus for getting pieces other than strong king
187 | close to weak king in EndgameEval1.
188 |
189 | 1999 January 14 [Don Cross]
190 | Updated coding style.
191 |
192 | 2001 January 4 [Don Cross]
193 | Proximity bonus for bishops and knights too (but 1/12 as much).
194 | Now use special KingPos tables when checkmate must be performed
195 | with a bishop. This way, we don't accidentally force the king
196 | into the wrong color corner.
197 |
198 | */
199 |
200 |
--------------------------------------------------------------------------------
/src/fixtree.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "chess.h"
4 | #include "lrntree.h"
5 |
6 | int main()
7 | {
8 | LearnTree tree;
9 | tree.open ( DEFAULT_CHENARD_TREE_FILENAME );
10 | LearnBranch branch;
11 |
12 | for ( INT32 offset=0; tree.read(offset,branch); offset++ )
13 | {
14 | if ( branch.child == 0xffff )
15 | branch.child = -1;
16 |
17 | if ( branch.sibling == 0xffff )
18 | branch.sibling = -1;
19 |
20 | if ( branch.winsAndLosses & 0x8000 )
21 | branch.winsAndLosses |= 0xffff0000;
22 |
23 | tree.write ( offset, branch );
24 | }
25 |
26 | return 0;
27 | }
28 |
29 | void ChessFatal ( const char *msg )
30 | {
31 | fprintf ( stderr, "%s\n", msg );
32 | exit(1);
33 | }
34 |
35 | /*
36 | $Log: fixtree.cpp,v $
37 | Revision 1.2 2006/03/20 20:44:10 dcross
38 | I finally figured out the weird slowness I have been seeing in Chenard accessing
39 | its experience tree. It turns out it only happens the first time it accessed the file
40 | chenard.tre after a reboot. It was caused by Windows XP thinking chenard.tre was
41 | an important system file, because of its extension:
42 | http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sr/sr/monitored_file_extensions.asp
43 | We write 36 bytes to the middle of the file, then close it
44 | So I have changed the filename from chenard.tre to chenard.trx.
45 | I also added DEFAULT_CHENARD_TREE_FILENAME in lrntree.h so that I can more
46 | easily rename this again if need be.
47 |
48 | Revision 1.1 2005/11/25 19:47:27 dcross
49 | Recovered lots of old chess source files from the dead!
50 | Found these on CDROM marked "14 September 1999".
51 | Added cvs log tag and moved old revision history after that.
52 |
53 | */
54 |
55 |
--------------------------------------------------------------------------------
/src/gamefile.h:
--------------------------------------------------------------------------------
1 | /*
2 | gamefile.h - Don Cross, January 2006.
3 |
4 | C++ classes to abstract the process to load chess moves from
5 | various kinds of files: old chenard GAM, PGN, or
6 | Yahoo game listing email text.
7 | */
8 |
9 |
10 | bool ReadFromFile ( FILE *, Move & ); // recycled old function
11 |
12 | enum PGNRESULT
13 | {
14 | PGNRESULT_UNKNOWN = 0,
15 | PGNRESULT_WHITE_WON,
16 | PGNRESULT_BLACK_WON,
17 | PGNRESULT_DRAW
18 | };
19 |
20 | struct PgnExtraInfo
21 | {
22 | char fen [256]; // set to "" if game started normally.
23 | PGNRESULT result;
24 | int whiteElo; // set to 0 if White's ELO is not specified in the PGN file
25 | int blackElo; // set to 0 if Black's ELO is not specified in the PGN file
26 | };
27 |
28 | bool GetNextPgnMove (
29 | FILE *file,
30 | char movestr[1+MAX_MOVE_STRLEN],
31 | PGN_FILE_STATE &state,
32 | PgnExtraInfo &info // will be zeroed out, then members will be set if new game is found. may be set with EOF return as special case, if game has no moves.
33 | );
34 |
35 |
36 | class tChessMoveStream
37 | {
38 | public:
39 | static tChessMoveStream *OpenFileForRead (const char *filename); // factory function for auto-detecting file format
40 |
41 | virtual ~tChessMoveStream()
42 | {
43 | }
44 |
45 | virtual bool GetNextMove(Move &, PGN_FILE_STATE &) = 0;
46 | };
47 |
48 |
49 | class tChessMoveFile: public tChessMoveStream
50 | {
51 | public:
52 | tChessMoveFile(FILE *_infile):
53 | infile(_infile)
54 | {
55 | }
56 |
57 | virtual ~tChessMoveFile()
58 | {
59 | if (infile)
60 | {
61 | fclose (infile);
62 | infile = NULL;
63 | }
64 | }
65 |
66 | protected:
67 | FILE *infile;
68 | ChessBoard board;
69 | };
70 |
71 |
72 | class tChessMoveFile_PGN: public tChessMoveFile
73 | {
74 | public:
75 | tChessMoveFile_PGN(FILE *_infile):
76 | tChessMoveFile(_infile)
77 | {
78 | }
79 |
80 | virtual bool GetNextMove(Move &, PGN_FILE_STATE &);
81 | };
82 |
83 |
84 | void SavePortableGameNotation (
85 | FILE *outfile,
86 | ChessBoard &refboard,
87 | const char *whiteName,
88 | const char *blackName
89 | );
90 |
91 |
92 | const char *GetWhitePlayerString(); // defined on per-project basis
93 | const char *GetBlackPlayerString(); // defined on per-project basis
94 |
95 |
96 | inline void SavePortableGameNotation (FILE *outfile, ChessBoard &board)
97 | {
98 | SavePortableGameNotation (
99 | outfile,
100 | board,
101 | GetWhitePlayerString(),
102 | GetBlackPlayerString()
103 | );
104 | }
105 |
106 |
107 | bool SaveGamePGN (
108 | ChessBoard &board,
109 | const char *filename,
110 | const char *whiteName,
111 | const char *blackName
112 | );
113 |
114 |
115 | bool SaveGamePGN (
116 | ChessBoard &board,
117 | const char *filename
118 | );
119 |
120 |
121 | /*
122 | $Log: gamefile.h,v $
123 | Revision 1.7 2008/12/01 23:08:53 Don.Cross
124 | Norm Pollock announced on the WinBoard forum that he has updated his PGN database:
125 | http://www.open-aurec.com/wbforum/viewtopic.php?t=49522
126 | http://www.hoflink.com/~npollock/chess.html
127 | This is just what I was looking for, so that I could beef up chenard.trx (training file).
128 | I modified the PGN scanner to recognize WhiteElo, BlackElo, and Result tags.
129 | I am using WhiteElo and BlackElo to decide whether a game is trustworthy enough to pretend like Chenard thought
130 | of the move itself, so that it will play that move in actual games, instead of just as a reference point for opponent moves.
131 | I am currently in the process of slurping an enormous amount of openings into chenard.trx.
132 | I decided to move GetNextPgnMove from board.cpp to gamefile.cpp, where it really belongs.
133 |
134 | Revision 1.6 2008/11/12 23:06:07 Don.Cross
135 | Massive refactoring of the concept of an 'editedFlag' in ChessBoard.
136 | Now instead of just saying the board was edited, we will always remember the most recent position
137 | after which there are no more pseudo-moves representing edit actions.
138 | This allows us to save/load PGN files based on edited positions.
139 | More work needs to be done:
140 | - Need to allow move undo/redo to work in edited positions.
141 | - Because the game history is stored now inside the ChessBoard, it seems silly to have an external copy also!
142 | - Move numbers should be based on FEN when PGN is saved.
143 | In general, this is a scary change, so it needs more careful testing before being published.
144 |
145 | Revision 1.5 2006/01/28 21:44:16 dcross
146 | 1. Updated auto-save feature to use PGN format instead of old GAM format.
147 | This means we are sacrificing the ability to auto-save edited games, but I don't care.
148 | 2. Added a feature in class ChessGame: if the file 'game.counter' exists, auto-save
149 | to file based on integer counter it contains, and increment that counter in the file.
150 | This is so I no longer have to manually make up unique filenames and remember to
151 | save files when Chenard is in "combat mode".
152 | 3. Reworked PGN save functions so they can be shared by Win32 and portable versions.
153 | This requires all versions of Chenard to define functions GetWhitePlayerString and
154 | GetBlackPlayerString, so the players can be recorded in the PGN header.
155 |
156 | Revision 1.4 2006/01/20 21:12:40 dcross
157 | Renamed "loadpgn" command to "import", because now it can read in
158 | PGN, Yahoo, or GAM formats. To support PGN files that contain multiple
159 | game listings, I had to add a bool& parameter to GetMove method.
160 | Caller should check this and reset the board if needed.
161 |
162 | Revision 1.3 2006/01/18 19:58:11 dcross
163 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
164 | Now use C++ standard bool, true, false (none of which existed when I started this project).
165 |
166 | Revision 1.2 2006/01/14 22:21:00 dcross
167 | Added support for analyzing PGN games in addition to existing support for GAM and Yahoo formats.
168 |
169 | Revision 1.1 2006/01/14 17:13:06 dcross
170 | Added new class library for auto-detecting chess game file format and reading moves from it.
171 | Now using this new class for "portable.exe -a" game analysis.
172 | Still need to add support for PGN files: now it supports only GAM and Yahoo formats.
173 | Also would be nice to go back and make File/Open in winchen.exe use this stuff.
174 |
175 | */
176 |
--------------------------------------------------------------------------------
/src/human.cpp:
--------------------------------------------------------------------------------
1 | /*=========================================================================
2 |
3 | human.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | Contains the class HumanChessPlayer.
6 |
7 | =========================================================================*/
8 |
9 | #include "chess.h"
10 |
11 |
12 | HumanChessPlayer::HumanChessPlayer ( ChessUI &ui ):
13 | ChessPlayer(ui),
14 | automaticSingularMove (false)
15 | {
16 | }
17 |
18 |
19 | HumanChessPlayer::~HumanChessPlayer()
20 | {
21 | }
22 |
23 |
24 | bool HumanChessPlayer::GetMove (
25 | ChessBoard &board,
26 | Move &move,
27 | INT32 &timeSpent )
28 | {
29 | MoveList legalMoves;
30 | int i;
31 | int source, dest;
32 | INT32 startTime = ChessTime();
33 |
34 | board.GenMoves ( legalMoves );
35 | if ( legalMoves.num==1 && automaticSingularMove )
36 | {
37 | userInterface.NotifyUser (
38 | "You have only one legal move - it will be made for you." );
39 |
40 | userInterface.DisplayMove ( board, move = legalMoves.m[0] );
41 | timeSpent = 0;
42 | return true;
43 | }
44 |
45 | for(;;) // keep looping until UI returns a legal move
46 | {
47 | SQUARE promIndex = 0;
48 | if ( !userInterface.ReadMove ( board, source, dest, promIndex ) )
49 | {
50 | timeSpent = ChessTime() - startTime;
51 | return false;
52 | }
53 |
54 | // The following check allows certain UI tricks to work...
55 | if ( dest == SPECIAL_MOVE_NULL ||
56 | (dest & SPECIAL_MOVE_MASK) == SPECIAL_MOVE_EDIT )
57 | {
58 | move.source = source;
59 | move.dest = dest;
60 | move.score = 0;
61 | timeSpent = ChessTime() - startTime;
62 | return true;
63 | }
64 |
65 | // This checks for pawn promotion and stuff like that.
66 | move.Fix(board, legalMoves, source, dest, promIndex, userInterface);
67 |
68 | // Regenerate legal moves in case they edited the board.
69 | board.GenMoves(legalMoves);
70 |
71 | // See if the move we just read is legal!
72 | for ( i=0; i < legalMoves.num; i++ )
73 | {
74 | if ( move == legalMoves.m[i] )
75 | {
76 | // We found the move in the list of legal moves.
77 | // Therefore, the move must be legal.
78 | timeSpent = ChessTime() - startTime;
79 | return true;
80 | }
81 | }
82 | }
83 | }
84 |
85 |
86 | /*
87 | $Log: human.cpp,v $
88 | Revision 1.5 2008/11/06 22:25:06 Don.Cross
89 | Now ParseFancyMove accepts either PGN or longmove (e7e8q) style notation only.
90 | We tolerate of check '+' or checkmate '#' characters being absent or extraneous in the input.
91 | The former is especially important because I often see PGN notation where '+' is missing on checking moves.
92 | To allow for PGN input, I had to allow avoidance of the PromotePawn callback, so other code was changed as well.
93 | Version numbers are now always constently yyyy.mm.dd across all builds of Chenard!
94 |
95 | Revision 1.4 2006/01/18 19:58:11 dcross
96 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
97 | Now use C++ standard bool, true, false (none of which existed when I started this project).
98 |
99 | Revision 1.3 2005/11/23 21:30:30 dcross
100 | Removed all references to intersrv.com, because that ISP no longer exists!
101 | Changed references to Chenard web site and my email address to cosinekitty.com.
102 | (Still need to fix cosinekitty.com/chenard.html.)
103 |
104 | Revision 1.2 2005/11/23 21:14:40 dcross
105 | 1. Added cvs log tag at end of each source file.
106 | 2. Moved old manual revision history after cvs log tag.
107 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
108 |
109 |
110 |
111 | Revision history:
112 |
113 | 1993 August 30 [Don Cross]
114 | Changing pointers to references in the interfaces where
115 | appropriate.
116 |
117 | 1994 January 15 [Don Cross]
118 | Added check for SPECIAL_MOVE_NULL in HumanChessPlayer::GetMove().
119 |
120 | 1994 January 30 [Don Cross]
121 | Added check for SPECIAL_MOVE_EDIT.
122 |
123 | 1999 January 15 [Don Cross]
124 | Updated coding style.
125 |
126 | 1999 January 16 [Don Cross]
127 | Adding "automatic singular move" feature.
128 | This causes the computer to automatically make a move for
129 | a human player when there is only one legal move.
130 | This is intended to be of use when I'm playing Chenard
131 | in timed games, so that the computer can immediately
132 | start thinking about its next move.
133 | */
134 |
135 |
--------------------------------------------------------------------------------
/src/ichess.h:
--------------------------------------------------------------------------------
1 | /*======================================================================================
2 |
3 | ichess.h - Copyright (C) 1999-2005 by Don Cross
4 |
5 | Win32 version of InternetChessPlayer.
6 | Allows two instances of Chenard to play chess over TCP/IP using WinSock.
7 |
8 | ======================================================================================*/
9 | #ifndef __ddc_chenard_ichess_h
10 | #define __ddc_chenard_ichess_h
11 |
12 |
13 | #define DEFAULT_CHENARD_PORT 5387
14 |
15 |
16 | struct InternetConnectionInfo
17 | {
18 | SOCKET commSocket;
19 | int waitForClient;
20 | };
21 |
22 |
23 | class InternetChessPlayer: public ChessPlayer
24 | {
25 | public:
26 | InternetChessPlayer ( ChessUI &, const InternetConnectionInfo & );
27 | ~InternetChessPlayer();
28 |
29 | static void SetServerPortNumber ( unsigned newPortNumber );
30 | static unsigned QueryServerPortNumber();
31 |
32 | virtual bool GetMove ( ChessBoard &, Move &, INT32 &timeSpent );
33 | virtual void InformResignation();
34 | virtual void InformGameOver ( const ChessBoard & );
35 |
36 | protected:
37 | bool send ( const ChessBoard & );
38 | bool receive ( ChessBoard &board, Move &move );
39 |
40 | private:
41 | static unsigned ServerPortNumber;
42 |
43 | private:
44 | InternetConnectionInfo connectInfo;
45 | };
46 |
47 |
48 | #endif // __ddc_chenard_ichess_h
49 |
50 | /*
51 | $Log: ichess.h,v $
52 | Revision 1.4 2006/01/18 19:58:11 dcross
53 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
54 | Now use C++ standard bool, true, false (none of which existed when I started this project).
55 |
56 | Revision 1.3 2005/11/23 21:30:30 dcross
57 | Removed all references to intersrv.com, because that ISP no longer exists!
58 | Changed references to Chenard web site and my email address to cosinekitty.com.
59 | (Still need to fix cosinekitty.com/chenard.html.)
60 |
61 | Revision 1.2 2005/11/23 21:14:41 dcross
62 | 1. Added cvs log tag at end of each source file.
63 | 2. Moved old manual revision history after cvs log tag.
64 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
65 |
66 | */
67 |
68 |
--------------------------------------------------------------------------------
/src/kbd.h:
--------------------------------------------------------------------------------
1 | /*--------------------------------------------------------------------------
2 | ukbd.h - Donald Cross, March 1988.
3 | Copyright (C) 1988-1996 by Donald Cross & Bill Brown
4 | Keyboard stuff for USCREEN libraries.
5 |
6 | KeyPressed() added by Bill Brown, June 1988.
7 | ----------------------------------------------------------------------------*/
8 |
9 | #ifndef __UKBD__
10 | #define __UKBD__
11 |
12 | int far KeyPressed(void);
13 |
14 |
15 | /*----- Macros which return the status of shift-type keys . . . -----*/
16 |
17 | #define CAPS 64
18 | #define NUM 32
19 | #define SCROLL 16
20 | #define ALT 8
21 | #define CTRL 4
22 | #define LSHIFT 2
23 | #define RSHIFT 1
24 | #define SHIFT 3
25 |
26 | #define capsactive() (bioskey(2) & CAPS)
27 | #define numactive() (bioskey(2) & NUM)
28 | #define scrollactive() (bioskey(2) & SCROLL)
29 | #define altpressed() (bioskey(2) & ALT)
30 | #define ctrlpressed() (bioskey(2) & CTRL)
31 | #define lshiftpressed() (bioskey(2) & LSHIFT)
32 | #define rshiftpressed() (bioskey(2) & RSHIFT)
33 | #define shiftpressed() (bioskey(2) & SHIFT)
34 |
35 | #define keystate() peekb(0x0000,0x0418)
36 |
37 | #define capspressed() (keystate() & CAPS)
38 | #define numpressed() (keystate() & NUM)
39 | #define scrollpressed() (keystate() & SCROLL)
40 |
41 | /*----------------------------------------------------------------------*/
42 |
43 |
44 | /* Function keys . . . */
45 |
46 | #define F1 (59<<8)
47 | #define F2 (60<<8)
48 | #define F3 (61<<8)
49 | #define F4 (62<<8)
50 | #define F5 (63<<8)
51 | #define F6 (64<<8)
52 | #define F7 (65<<8)
53 | #define F8 (66<<8)
54 | #define F9 (67<<8)
55 | #define F10 (68<<8)
56 |
57 | /* Shifted function keys . . . */
58 |
59 | #define S_F1 (84<<8)
60 | #define S_F2 (85<<8)
61 | #define S_F3 (86<<8)
62 | #define S_F4 (87<<8)
63 | #define S_F5 (88<<8)
64 | #define S_F6 (89<<8)
65 | #define S_F7 (90<<8)
66 | #define S_F8 (91<<8)
67 | #define S_F9 (92<<8)
68 | #define S_F10 (93<<8)
69 |
70 | /* Control function keys, such as - . . . */
71 |
72 | #define C_F1 (94<<8)
73 | #define C_F2 (95<<8)
74 | #define C_F3 (96<<8)
75 | #define C_F4 (97<<8)
76 | #define C_F5 (98<<8)
77 | #define C_F6 (99<<8)
78 | #define C_F7 (100<<8)
79 | #define C_F8 (101<<8)
80 | #define C_F9 (102<<8)
81 | #define C_F10 (103<<8)
82 |
83 | /* Alt function keys, such as - . . . */
84 |
85 | #define A_F1 (104<<8)
86 | #define A_F2 (105<<8)
87 | #define A_F3 (106<<8)
88 | #define A_F4 (107<<8)
89 | #define A_F5 (108<<8)
90 | #define A_F6 (109<<8)
91 | #define A_F7 (110<<8)
92 | #define A_F8 (111<<8)
93 | #define A_F9 (112<<8)
94 | #define A_F10 (113<<8)
95 |
96 | /* Other Alt-keys . . . */
97 |
98 | #define A_1 (120<<8)
99 | #define A_2 (121<<8)
100 | #define A_3 (122<<8)
101 | #define A_4 (123<<8)
102 | #define A_5 (124<<8)
103 | #define A_6 (125<<8)
104 | #define A_7 (126<<8)
105 | #define A_8 (127<<8)
106 | #define A_9 (128<<8)
107 | #define A_0 (129<<8)
108 |
109 | #define A_HYPHEN (130<<8)
110 | #define A_Q (16<<8)
111 | #define A_W (17<<8)
112 | #define A_E (18<<8)
113 | #define A_R (19<<8)
114 | #define A_T (20<<8)
115 | #define A_Y (21<<8)
116 | #define A_U (22<<8)
117 | #define A_I (23<<8)
118 | #define A_O (24<<8)
119 | #define A_P (25<<8)
120 |
121 | #define A_A (30<<8)
122 | #define A_S (31<<8)
123 | #define A_D (32<<8)
124 | #define A_F (33<<8)
125 | #define A_G (34<<8)
126 | #define A_H (35<<8)
127 | #define A_J (36<<8)
128 | #define A_K (37<<8)
129 | #define A_L (38<<8)
130 |
131 | #define A_Z (44<<8)
132 | #define A_X (45<<8)
133 | #define A_C (46<<8)
134 | #define A_V (47<<8)
135 | #define A_B (48<<8)
136 | #define A_N (49<<8)
137 | #define A_M (50<<8)
138 |
139 | /* - . . . */
140 |
141 | #define S_TAB (15<<8)
142 |
143 | /* Numeric keypad special keys . . . */
144 |
145 | #define HOME (71<<8)
146 | #define UPAR (72<<8)
147 | #define PGUP (73<<8)
148 | #define LAR (75<<8)
149 | #define RAR (77<<8)
150 | #define END (79<<8)
151 | #define DOWNAR (80<<8)
152 | #define PGDN (81<<8)
153 | #define INSERT (82<<8)
154 | #define DELETE (83<<8)
155 |
156 | /* More control keys which return extended scan codes . . . */
157 |
158 | #define C_LAR (115<<8)
159 | #define C_RAR (116<<8)
160 | #define C_END (117<<8)
161 | #define C_PGDN (118<<8)
162 | #define C_HOME (119<<8)
163 | #define C_PGUP (132<<8)
164 |
165 | /* Commonly used keys which do not generate extended scan codes . . . */
166 |
167 | #define BACKSPACE 8
168 | #define SPACE 32
169 | #define ENTER 13
170 | #define ESCAPE 27
171 | #define TAB 9
172 |
173 | /* Control-alpha keys . . .
174 | (No, I didn't type all these in. I wrote a program to do it!) */
175 |
176 | #define C_A 1
177 | #define C_B 2
178 | #define C_C 3
179 | #define C_D 4
180 | #define C_E 5
181 | #define C_F 6
182 | #define C_G 7
183 | #define C_H 8
184 | #define C_I 9
185 | #define C_J 10
186 | #define C_K 11
187 | #define C_L 12
188 | #define C_M 13
189 | #define C_N 14
190 | #define C_O 15
191 | #define C_P 16
192 | #define C_Q 17
193 | #define C_R 18
194 | #define C_S 19
195 | #define C_T 20
196 | #define C_U 21
197 | #define C_V 22
198 | #define C_W 23
199 | #define C_X 24
200 | #define C_Y 25
201 | #define C_Z 26
202 |
203 | #endif
204 |
205 | /*
206 | $Log: kbd.h,v $
207 | Revision 1.1 2005/11/25 19:47:27 dcross
208 | Recovered lots of old chess source files from the dead!
209 | Found these on CDROM marked "14 September 1999".
210 | Added cvs log tag and moved old revision history after that.
211 |
212 | */
213 |
214 |
--------------------------------------------------------------------------------
/src/lichess.h:
--------------------------------------------------------------------------------
1 | /*===========================================================================
2 |
3 | lichess.h - Copyright (C) 1999 by Don Cross
4 |
5 | Win32 version of InternetChessPlayer.
6 | Allows two instances of Chenard to play chess over TCP/IP using WinSock.
7 |
8 | ===========================================================================*/
9 | #ifndef __ddc_chenard_lichess_h
10 | #define __ddc_chenard_lichess_h
11 |
12 |
13 | #define DEFAULT_CHENARD_PORT 5387
14 |
15 |
16 | class InternetChessPlayer: public ChessPlayer
17 | {
18 | public:
19 | InternetChessPlayer ( ChessUI & );
20 | ~InternetChessPlayer();
21 |
22 | int serverConnect ( ChessSide remoteSide );
23 |
24 | static void SetServerPortNumber ( unsigned newPortNumber );
25 | static unsigned QueryServerPortNumber();
26 |
27 | virtual bool GetMove ( ChessBoard &, Move &, INT32 &timeSpent );
28 | virtual void InformResignation();
29 | virtual void InformGameOver ( const ChessBoard & );
30 |
31 | protected:
32 | bool send ( const ChessBoard & );
33 | bool receive ( ChessBoard &board, Move &move );
34 |
35 | private:
36 | static unsigned ServerPortNumber;
37 |
38 | private:
39 | int commSocket;
40 | int listenSocket;
41 | };
42 |
43 |
44 | #endif // __ddc_chenard_lichess_h
45 |
46 | /*
47 | $Log: lichess.h,v $
48 | Revision 1.2 2006/01/18 19:58:12 dcross
49 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
50 | Now use C++ standard bool, true, false (none of which existed when I started this project).
51 |
52 | Revision 1.1 2005/11/25 19:47:27 dcross
53 | Recovered lots of old chess source files from the dead!
54 | Found these on CDROM marked "14 September 1999".
55 | Added cvs log tag and moved old revision history after that.
56 |
57 |
58 | Revision history:
59 |
60 | 1999 January 23 [Don Cross]
61 | Ported from WinSock version (ichess.h) to Linux environment.
62 |
63 | */
64 |
65 |
--------------------------------------------------------------------------------
/src/linuxtime.cpp:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | linuxtime.cpp - Copyright (C) 1993-1999 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | Version of ChessTime() for Linux version of Chenard.
8 |
9 | =======================================================================*/
10 |
11 | #include
12 | #include "chess.h"
13 |
14 |
15 | static double GetAbsoluteTime()
16 | {
17 | timeval now;
18 | gettimeofday ( &now, 0 );
19 | return 100.0*double(now.tv_sec) + double(now.tv_usec)/10000.0;
20 | }
21 |
22 |
23 | INT32 ChessTime()
24 | {
25 | static double baseTime = 0; // abs time at first call to ChessTime()
26 | static bool firstCall = true; // is this the first call to ChessTime()?
27 |
28 | if ( firstCall )
29 | {
30 | firstCall = false;
31 | baseTime = GetAbsoluteTime();
32 | return 0;
33 | }
34 |
35 | return INT32 ( GetAbsoluteTime() - baseTime );
36 | }
37 |
38 |
39 | /*
40 | $Log: linuxtime.cpp,v $
41 | Revision 1.2 2008/11/07 20:31:54 Don.Cross
42 | Changed int to bool for local variable firstCall.
43 |
44 | Revision 1.1 2005/11/25 19:47:27 dcross
45 | Recovered lots of old chess source files from the dead!
46 | Found these on CDROM marked "14 September 1999".
47 | Added cvs log tag and moved old revision history after that.
48 |
49 |
50 | Revision history:
51 |
52 | 1999 January 15 [Don Cross]
53 | Found out that 'bool' type is still not supported on certain
54 | Unix C++ compilers (e.g. Sun Solaris). Replacing 'bool' with
55 | 'int', etc.
56 |
57 | 1999 January 1 [Don Cross]
58 | Fixed bug where ChessTime() was "wrapping around" to
59 | absurdly large values. Was incorrectly using the clock()
60 | function, which measures processor time, not real time.
61 | Doesn't look like constructor for static object was being called,
62 | perhaps because the object was not being used anywhere (???).
63 |
64 | 1998 December 25 [Don Cross]
65 | Started writing.
66 |
67 | */
68 |
69 |
--------------------------------------------------------------------------------
/src/material.cpp:
--------------------------------------------------------------------------------
1 | /*============================================================================
2 |
3 | material.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | Contains non-linear transformation lookup table for
6 | material on a chess board.
7 |
8 | This is important for implementing a bonus for trading when
9 | ahead in material, and a penalty for trading when behind in
10 | material.
11 |
12 | ============================================================================*/
13 |
14 | #include
15 |
16 | #include "chess.h"
17 |
18 | #define INITIAL_MATERIAL \
19 | (KING_VAL + QUEEN_VAL + 2*ROOK_VAL + 2*BISHOP_VAL + 2*KNIGHT_VAL + 8*PAWN_VAL)
20 |
21 | #define MAX_MATERIAL_POSSIBLE \
22 | (KING_VAL + 9*QUEEN_VAL + 2*ROOK_VAL + 2*BISHOP_VAL + 2*KNIGHT_VAL)
23 |
24 |
25 | SCORE MaterialData [MAX_MATERIAL_POSSIBLE + 1];
26 |
27 |
28 | SCORE MaterialEval ( SCORE wmaterial, SCORE bmaterial )
29 | {
30 | #if 0
31 | if ( wmaterial < KING_VAL
32 | || wmaterial > MAX_MATERIAL_POSSIBLE
33 | || bmaterial < KING_VAL
34 | || bmaterial > MAX_MATERIAL_POSSIBLE )
35 | {
36 | ChessFatal ( "Invalid material value in MaterialEval()" );
37 | }
38 | #endif
39 |
40 | return MaterialData[wmaterial] - MaterialData[bmaterial];
41 | }
42 |
43 |
44 | class MaterialDataInitializer
45 | {
46 | public:
47 | MaterialDataInitializer();
48 | };
49 |
50 |
51 | MaterialDataInitializer::MaterialDataInitializer()
52 | {
53 | SCORE x;
54 |
55 | const double D = 1.4; // slope at queen down from init material
56 |
57 | const double A = (D - 1.0) / (2.0 * INITIAL_MATERIAL);
58 | const double B = 0.5 / A + INITIAL_MATERIAL;
59 | const double C = 0.25 / A + INITIAL_MATERIAL;
60 |
61 | for ( x=KING_VAL; x <= MAX_MATERIAL_POSSIBLE; x++ )
62 | {
63 | double g = -A * (x - B) * (x - B) + C;
64 | MaterialData[x] = SCORE ( 10.0 * g + 0.5 );
65 | }
66 | }
67 |
68 | static MaterialDataInitializer bob; // Bob loves you!!!
69 |
70 |
71 | /*
72 | $Log: material.cpp,v $
73 | Revision 1.3 2005/11/23 21:30:30 dcross
74 | Removed all references to intersrv.com, because that ISP no longer exists!
75 | Changed references to Chenard web site and my email address to cosinekitty.com.
76 | (Still need to fix cosinekitty.com/chenard.html.)
77 |
78 | Revision 1.2 2005/11/23 21:14:41 dcross
79 | 1. Added cvs log tag at end of each source file.
80 | 2. Moved old manual revision history after cvs log tag.
81 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
82 |
83 | */
84 |
85 |
--------------------------------------------------------------------------------
/src/npchess.h:
--------------------------------------------------------------------------------
1 | /*
2 | npchess.h - Copyright (C) 2006 Don Cross. All Rights Reserved.
3 |
4 | class NamedPipeChessPlayer.
5 | */
6 |
7 | #if SUPPORT_NAMED_PIPE
8 |
9 | class NamedPipeChessPlayer: public ChessPlayer
10 | {
11 | public:
12 | NamedPipeChessPlayer (ChessUI &_ui, const char *_MachineName);
13 | virtual ~NamedPipeChessPlayer();
14 |
15 | //-------------------------------------------------------------
16 | // The following function should store the player's move
17 | // and return true, or return false to quit the game.
18 | // This function will not be called if it is already the
19 | // end of the game.
20 | //-------------------------------------------------------------
21 | virtual bool GetMove (ChessBoard &, Move &, INT32 &timeSpent);
22 |
23 | //-------------------------------------------------------------
24 | // The following member function was added to support
25 | // class InternetChessPlayer. When a player resigns,
26 | // this member function is called for the other player.
27 | // This way, a remote player will immediately know that
28 | // the local player has resigned.
29 | //-------------------------------------------------------------
30 | virtual void InformResignation();
31 |
32 | //-------------------------------------------------------------
33 | // The following member function is called whenever the
34 | // game has ended due to the opponent's move. This was
35 | // added so that InternetChessPlayer objects (representing
36 | // a remote player) have a way to receive the final move.
37 | //-------------------------------------------------------------
38 | virtual void InformGameOver (const ChessBoard &);
39 |
40 | private:
41 | char MachineName [256]; // name of server, e.g. "\\computer"
42 | HANDLE NamedPipe;
43 | };
44 |
45 |
46 | #endif // SUPPORT_NAMED_PIPE
47 |
48 | /*
49 | $Log: npchess.h,v $
50 | Revision 1.1 2006/02/25 22:22:19 dcross
51 | Added support for connecting to Flywheel named pipe server as a Chenard chess player.
52 | This allows me to use my new Flywheel engine via the Chenard GUI.
53 |
54 | */
55 |
--------------------------------------------------------------------------------
/src/obsolete/msdos/doscga.cpp:
--------------------------------------------------------------------------------
1 | /*=========================================================================
2 |
3 | doscga.cpp - Copyright (C) 1993-1998 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | Contains main() for MS-DOS CGA version of Chenard.
8 |
9 | =========================================================================*/
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | #include "chess.h"
16 | #include "uicga.h"
17 |
18 | unsigned _stklen = 0x6000;
19 |
20 | #pragma argsused
21 | int main ( int argc, char *argv[] )
22 | {
23 | extern bool sound_flag;
24 | sound_flag = false;
25 |
26 | printf ( "\n"
27 | "Chenard / MS-DOS CGA version (22 June 1997)\n"
28 | "A chess program by Don Cross \n"
29 | "http://www.intersrv.com/~dcross\n\n" );
30 |
31 | ChessBoard theBoard;
32 | ChessUI_dos_cga theUserInterface;
33 | ChessGame theGame ( theBoard, theUserInterface );
34 | theGame.Play();
35 |
36 | return 0;
37 | }
38 |
39 |
40 | void ChessFatal ( const char *message )
41 | {
42 | fprintf ( stderr, "Chess fatal:\n%s\n", message );
43 |
44 | FILE *errorLog = fopen ( "doscga.err", "wt" );
45 | if ( errorLog )
46 | {
47 | fprintf ( errorLog, "Chess fatal:\n%s\n", message );
48 | fclose ( errorLog );
49 | }
50 |
51 | exit(1);
52 | }
53 |
54 |
55 | /*
56 | $Log: doscga.cpp,v $
57 | Revision 1.2 2006/01/18 19:58:11 dcross
58 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
59 | Now use C++ standard bool, true, false (none of which existed when I started this project).
60 |
61 | Revision 1.1 2005/11/25 19:47:27 dcross
62 | Recovered lots of old chess source files from the dead!
63 | Found these on CDROM marked "14 September 1999".
64 | Added cvs log tag and moved old revision history after that.
65 |
66 |
67 |
68 | Revision history:
69 |
70 | 1996 February 28 [Don Cross]
71 | Put in my new e-mail address, etc.
72 |
73 | 1993 August 30 [Don Cross]
74 | Changing pointers to references in the interfaces where
75 | appropriate.
76 |
77 | */
78 |
--------------------------------------------------------------------------------
/src/obsolete/msdos/dostime.cpp:
--------------------------------------------------------------------------------
1 | /*=========================================================================
2 |
3 | dostime.cpp - Copyright (C) 1993-1996 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | MS-DOS version of chess time stuff.
8 |
9 | =========================================================================*/
10 |
11 | #include
12 | #include "chess.h"
13 |
14 | static unsigned long far *timer = (unsigned long far *) MK_FP(0,0x46C);
15 | static unsigned long progStartTime;
16 |
17 | INT32 ChessTime()
18 | {
19 | INT32 t = ((*timer - progStartTime) * 1000) / 182;
20 |
21 | return t;
22 | }
23 |
24 |
25 | class DosTimeInitializer
26 | {
27 | public:
28 | DosTimeInitializer()
29 | {
30 | progStartTime = *timer;
31 | }
32 | };
33 |
34 |
35 | static DosTimeInitializer Kudabuda;
36 |
37 |
38 | /*
39 | $Log: dostime.cpp,v $
40 | Revision 1.1 2005/11/25 19:47:27 dcross
41 | Recovered lots of old chess source files from the dead!
42 | Found these on CDROM marked "14 September 1999".
43 | Added cvs log tag and moved old revision history after that.
44 |
45 | */
46 |
47 |
--------------------------------------------------------------------------------
/src/obsolete/msdos/dosvga.cpp:
--------------------------------------------------------------------------------
1 | /*=========================================================================
2 |
3 | dosvga.cpp - Copyright (C) 1993-1996 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | Contains main() for MS-DOS VGA version of Chenard.
8 |
9 | =========================================================================*/
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | #include "chess.h"
16 | #include "uivga.h"
17 |
18 | unsigned _stklen = 0x6000;
19 |
20 | text_info StartupTextInfo;
21 |
22 | void Advertise()
23 | {
24 | printf ( "\n"
25 | "Chenard / MS-DOS VGA version (22 June 1997)\n"
26 | "A chess program by Don Cross \n"
27 | "http://www.intersrv.com/~dcross\n\n" );
28 | }
29 |
30 |
31 | void ExitCode()
32 | {
33 | textmode ( StartupTextInfo.currmode );
34 | Advertise();
35 | }
36 |
37 |
38 | #pragma argsused
39 | int main ( int argc, char *argv[] )
40 | {
41 | gettextinfo ( &StartupTextInfo );
42 | atexit ( ExitCode );
43 |
44 | extern bool sound_flag;
45 | sound_flag = false;
46 |
47 | extern int Learn_Output;
48 | Learn_Output = 0;
49 | Advertise();
50 |
51 | ChessBoard theBoard;
52 | ChessUI_dos_vga theUserInterface;
53 | ChessGame theGame ( theBoard, theUserInterface );
54 | theGame.Play();
55 |
56 | Advertise();
57 |
58 | return 0;
59 | }
60 |
61 |
62 | void ChessFatal ( const char *message )
63 | {
64 | fprintf ( stderr, "Chess fatal:\n%s\n", message );
65 |
66 | FILE *errorLog = fopen ( "doscga.err", "wt" );
67 | if ( errorLog )
68 | {
69 | fprintf ( errorLog, "Chess fatal:\n%s\n", message );
70 | fclose ( errorLog );
71 | }
72 |
73 | exit(1);
74 | }
75 |
76 |
77 | /*
78 | $Log: dosvga.cpp,v $
79 | Revision 1.2 2006/01/18 19:58:11 dcross
80 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
81 | Now use C++ standard bool, true, false (none of which existed when I started this project).
82 |
83 | Revision 1.1 2005/11/25 19:47:27 dcross
84 | Recovered lots of old chess source files from the dead!
85 | Found these on CDROM marked "14 September 1999".
86 | Added cvs log tag and moved old revision history after that.
87 |
88 |
89 | Revision history:
90 |
91 | 1996 March 6 [Don Cross]
92 | Added code to preserve original video mode upon exit.
93 |
94 | 1996 March 2 [Don Cross]
95 | Copied from doscga.cpp to make a new VGA version of Chenard.
96 |
97 | 1996 February 28 [Don Cross]
98 | Put in my new e-mail address, etc.
99 |
100 | 1993 August 30 [Don Cross]
101 | Changing pointers to references in the interfaces where
102 | appropriate.
103 |
104 | */
105 |
106 |
--------------------------------------------------------------------------------
/src/obsolete/msdos/uicga.h:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | uicga.h - Copyright (C) 1993-1996 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | User interface header file for MS-DOS CGA version of chess.
8 |
9 | =======================================================================*/
10 |
11 |
12 | // This is a special UI for MS-DOS, re-using the UI code from
13 | // Chessola, Chester, and LanChess...
14 |
15 | #define CHESSUI_DOS_CGA
16 |
17 | class ChessUI_dos_cga: public ChessUI
18 | {
19 | public:
20 | ChessUI_dos_cga();
21 | ~ChessUI_dos_cga();
22 |
23 | #ifdef NO_SEARCH
24 | bool Activate();
25 | #endif
26 |
27 | ChessPlayer *CreatePlayer ( ChessSide );
28 | bool ReadMove ( ChessBoard &, int &source, int &dest );
29 | SQUARE PromotePawn ( int PawnDest, ChessSide );
30 | void DisplayMove ( ChessBoard &, Move );
31 | void RecordMove ( ChessBoard &, Move, INT32 thinkTime );
32 | void DrawBoard ( const ChessBoard & );
33 | void ReportEndOfGame ( ChessSide winner );
34 | void DisplayBestMoveSoFar ( const ChessBoard &, Move bestSoFar, int level );
35 | void DisplayCurrentMove ( const ChessBoard &, Move move, int level );
36 | void PredictMate ( int numMoves );
37 |
38 | void ReportComputerStats ( INT32 thinkTime,
39 | UINT32 nodesVisited,
40 | UINT32 nodesEvaluated,
41 | UINT32 nodesGenerated,
42 | int fwSearchDepth,
43 | UINT32 vis [NODES_ARRAY_SIZE],
44 | UINT32 gen [NODES_ARRAY_SIZE] );
45 |
46 | void Resign ( ChessSide ) {}
47 |
48 | private:
49 | bool graphics_initialized;
50 |
51 | Move FixMove ( const ChessBoard &, int source, int dest );
52 | };
53 |
54 |
55 | void sqrborder ( int x, int y, int grcolor );
56 | void drawsqr ( SQUARE p, int x, int y );
57 | void initscreen ();
58 | void drawgrid ();
59 | void drawboard ( const SQUARE board[144] );
60 | void refreshboard ( const SQUARE board[144] );
61 | void flashsqr ( int x, int y, SQUARE oldpiece, SQUARE newpiece, int keywait );
62 | void drawmove ( const SQUARE b[144], int ofs, int disp );
63 | int getkey (void);
64 | int select ( char *options );
65 | void displaynotation ( char *notation, unsigned long thinkTime, int side );
66 |
67 |
68 | /*
69 | $Log: uicga.h,v $
70 | Revision 1.2 2006/01/18 19:58:15 dcross
71 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
72 | Now use C++ standard bool, true, false (none of which existed when I started this project).
73 |
74 | Revision 1.1 2005/11/25 19:47:28 dcross
75 | Recovered lots of old chess source files from the dead!
76 | Found these on CDROM marked "14 September 1999".
77 | Added cvs log tag and moved old revision history after that.
78 |
79 | */
80 |
81 |
--------------------------------------------------------------------------------
/src/obsolete/msdos/uivga.h:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | uivga.h - Copyright (C) 1993-1996 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | Mutated from uicga.h by Don Cross, 24 April 1992.
8 |
9 | =======================================================================*/
10 |
11 | // This is a special UI for MS-DOS, re-using the UI code from
12 | // Chessola, Chester, and LanChess...
13 |
14 |
15 | class ChessUI_dos_vga: public ChessUI
16 | {
17 | public:
18 | ChessUI_dos_vga();
19 | ~ChessUI_dos_vga();
20 |
21 | #ifdef NO_SEARCH
22 | bool Activate();
23 | #endif
24 |
25 | ChessPlayer *CreatePlayer ( ChessSide );
26 | bool ReadMove ( ChessBoard &, int &source, int &dest );
27 | SQUARE PromotePawn ( int PawnDest, ChessSide );
28 | void DisplayMove ( ChessBoard &, Move );
29 | void RecordMove ( ChessBoard &, Move, INT32 thinkTime );
30 | void DrawBoard ( const ChessBoard & );
31 | void ReportEndOfGame ( ChessSide winner );
32 | void DisplayBestMoveSoFar ( const ChessBoard &, Move bestSoFar, int level );
33 | void DisplayCurrentMove ( const ChessBoard &, Move move, int level );
34 | void PredictMate ( int numMoves );
35 |
36 | void ReportComputerStats ( INT32 thinkTime,
37 | UINT32 nodesVisited,
38 | UINT32 nodesEvaluated,
39 | UINT32 nodesGenerated,
40 | int fwSearchDepth,
41 | UINT32 vis [NODES_ARRAY_SIZE],
42 | UINT32 gen [NODES_ARRAY_SIZE] );
43 |
44 | void Resign ( ChessSide, QuitGameReason ) {}
45 |
46 | void DebugPly ( int depth, ChessBoard &, Move );
47 | void DebugExit ( int depth, ChessBoard &, SCORE );
48 | void NotifyUser ( const char *message );
49 | void ReportSpecial ( const char *message );
50 |
51 | private:
52 | bool graphics_initialized;
53 | bool debugSearchFlag;
54 |
55 | Move FixMove ( const ChessBoard &, int source, int dest );
56 | };
57 |
58 |
59 | void sqrborder ( int x, int y, int grcolor );
60 | void drawsqr ( SQUARE p, int x, int y );
61 | void initscreen ();
62 | void drawgrid ();
63 | void drawboard ( const SQUARE board[144] );
64 | void refreshboard ( const SQUARE board[144] );
65 | void flashsqr ( int x, int y, SQUARE oldpiece, SQUARE newpiece, int keywait );
66 | void drawmove ( const SQUARE b[144], int ofs, int disp );
67 | int getkey (void);
68 | int select ( char *options );
69 | void displaynotation ( char *notation, unsigned long thinkTime, int side );
70 |
71 |
72 | /*
73 | $Log: uivga.h,v $
74 | Revision 1.2 2006/01/18 19:58:16 dcross
75 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
76 | Now use C++ standard bool, true, false (none of which existed when I started this project).
77 |
78 | Revision 1.1 2005/11/25 19:47:28 dcross
79 | Recovered lots of old chess source files from the dead!
80 | Found these on CDROM marked "14 September 1999".
81 | Added cvs log tag and moved old revision history after that.
82 |
83 |
84 | Revision history:
85 |
86 | 1999 February 14 [Don Cross]
87 | Bringing up to date with 32-bit code base.
88 | Adding ChessUI_dos_vga::ReportSpecial and
89 | ChessUI_dos_vga::NotifyUser.
90 |
91 | */
92 |
--------------------------------------------------------------------------------
/src/player.cpp:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | player.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | =======================================================================*/
6 |
7 | #include "chess.h"
8 |
9 | ChessPlayer::ChessPlayer ( ChessUI &ui )
10 | : userInterface(ui)
11 | , quitReason(qgr_resign)
12 | {
13 | }
14 |
15 |
16 | ChessPlayer::~ChessPlayer()
17 | {
18 | }
19 |
20 | /*
21 | $Log: player.cpp,v $
22 | Revision 1.3 2005/11/23 21:30:30 dcross
23 | Removed all references to intersrv.com, because that ISP no longer exists!
24 | Changed references to Chenard web site and my email address to cosinekitty.com.
25 | (Still need to fix cosinekitty.com/chenard.html.)
26 |
27 | Revision 1.2 2005/11/23 21:14:42 dcross
28 | 1. Added cvs log tag at end of each source file.
29 | 2. Moved old manual revision history after cvs log tag.
30 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
31 |
32 |
33 | Revision history:
34 |
35 | 1993 August 30 [Don Cross]
36 | Changing pointers to references in the interfaces where
37 | appropriate.
38 |
39 | */
40 |
41 |
--------------------------------------------------------------------------------
/src/profiler.cpp:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | profiler.cpp - Copyright (C) 1998-2005 by Don Cross
4 |
5 | Contains an execution profiler for Chenard.
6 | This should help me figure out which parts of the code
7 | need to be optimized.
8 |
9 | =======================================================================*/
10 | #include
11 |
12 | #include "chess.h"
13 | #include "winguich.h"
14 | #include "profiler.h"
15 |
16 | #define PROFILE_ARRAY_SIZE 64
17 | int ProfilerHitCount [PROFILE_ARRAY_SIZE];
18 | int ProfilerCallCount [PROFILE_ARRAY_SIZE];
19 | int ProfilerIndex = PX_UNDEFINED;
20 | static int TimerEnabledFlag = 0;
21 |
22 | #ifdef CHENARD_PROFILER
23 |
24 | void StartProfiler()
25 | {
26 | // reset the table of counters...
27 |
28 | for ( int i=0; i
12 | #include
13 | #include
14 | #include
15 | #include "chess.h"
16 |
17 |
18 | static void PlayWav ( const char *prefix )
19 | {
20 | char filename [256];
21 | strcpy ( filename, prefix );
22 | strcat ( filename, ".wav" );
23 | BOOL playResult = PlaySound ( filename, NULL, SND_FILENAME|SND_SYNC );
24 | }
25 |
26 |
27 | static void PlayWav ( char c )
28 | {
29 | char prefix[2];
30 | prefix[0] = c;
31 | prefix[1] = '\0';
32 | PlayWav ( prefix );
33 | }
34 |
35 |
36 | void Speak (const char *pgn)
37 | {
38 | int index = 0;
39 |
40 | if (pgn[0] == 'O')
41 | {
42 | // must be castling... either "O-O" or "O-O-O"
43 | if (pgn[1]=='-' && pgn[2]=='O')
44 | {
45 | if (pgn[3]=='-' && pgn[4]=='O')
46 | {
47 | PlayWav ("ooo");
48 | index = 5; // skip over "O-O-O", in case there is a "+", etc.
49 | }
50 | else
51 | {
52 | PlayWav ("oo");
53 | index = 3; // skip over "O-O", in case there is a "+", etc.
54 | }
55 | }
56 | else
57 | {
58 | assert (false); // not valid PGN notation!
59 | }
60 | }
61 |
62 | char c;
63 | while ((c = pgn[index++]) != '\0')
64 | {
65 | switch (c)
66 | {
67 | case 'N': PlayWav("knight"); break;
68 | case 'B': PlayWav("bishop"); break;
69 | case 'R': PlayWav("rook"); break;
70 | case 'Q': PlayWav("queen"); break;
71 | case 'K': PlayWav("king"); break;
72 | case 'x': PlayWav("takes"); break;
73 | case '+': PlayWav("check"); break;
74 | case '#': PlayWav("mate"); break;
75 | case '=': PlayWav("prom"); break;
76 |
77 | default:
78 | if ((c >= 'a' && c <= 'h') || (c >= '1' && c <= '8'))
79 | {
80 | PlayWav (c);
81 | }
82 | else
83 | {
84 | assert (false); // unexpected character
85 | }
86 | break;
87 | }
88 | }
89 | }
90 |
91 |
92 | /*
93 | // This is the old code that worked with goofy move notation.
94 | // It no longer works because Chenard generates PGN notation now.
95 |
96 | void Speak (const char *moveString)
97 | {
98 | // Piece being moved...
99 | const char *p = moveString;
100 | char c = *p++;
101 | int castled = 0;
102 | switch ( c )
103 | {
104 | case 'N': PlayWav("knight"); break;
105 | case 'B': PlayWav("bishop"); break;
106 | case 'R': PlayWav("rook"); break;
107 | case 'Q': PlayWav("queen"); break;
108 | case 'K': PlayWav("king"); break;
109 | case 'O':
110 | {
111 | castled = 1;
112 | // p now points to either "-O-O???" or "-O???"
113 | // 01234
114 | if ( p[2] == '-' && p[3] == 'O' )
115 | {
116 | PlayWav ( "ooo" );
117 | p += 4;
118 | }
119 | else
120 | {
121 | PlayWav ( "oo" );
122 | p += 2;
123 | }
124 | }
125 | default:
126 | {
127 | if ( c >= 'a' && c <= 'h' )
128 | {
129 | PlayWav ( c );
130 | PlayWav ( *p++ );
131 | }
132 | }
133 | }
134 |
135 | if ( !castled )
136 | {
137 | if ( *p && *p!='-' && *p!='x' )
138 | {
139 | PlayWav ( "at" );
140 | while ( *p && *p!='-' && *p!='x' )
141 | {
142 | PlayWav ( *p++ );
143 | }
144 | }
145 |
146 | if ( *p == '-' )
147 | {
148 | PlayWav ( "movesto" );
149 | ++p;
150 | }
151 | else if ( *p == 'x' )
152 | {
153 | PlayWav ( "takes" );
154 | ++p;
155 | }
156 |
157 | switch ( c = *p++ )
158 | {
159 | case 'N': PlayWav("knight"); break;
160 | case 'B': PlayWav("bishop"); break;
161 | case 'R': PlayWav("rook"); break;
162 | case 'Q': PlayWav("queen"); break;
163 | case 'K': PlayWav("king"); break;
164 | default:
165 | {
166 | if ( c >= 'a' && c <= 'h' )
167 | {
168 | PlayWav ( c );
169 | PlayWav ( *p++ );
170 | }
171 | }
172 | }
173 | }
174 |
175 | while ( *p )
176 | {
177 | if ( strcmp ( p, " mate" ) == 0 )
178 | {
179 | PlayWav ( "mate" );
180 | break;
181 | }
182 | else if ( strcmp ( p, " stale" ) == 0 )
183 | {
184 | PlayWav ( "stale" );
185 | break;
186 | }
187 | else if ( strcmp ( p, " e.p." ) == 0 )
188 | {
189 | PlayWav ( "ep" );
190 | break;
191 | }
192 | else switch ( c = *p++ )
193 | {
194 | case '/': PlayWav ("prom"); break;
195 | case '+': PlayWav ("check"); break;
196 | case 'N': PlayWav ("knight"); break;
197 | case 'B': PlayWav ("bishop"); break;
198 | case 'R': PlayWav ("rook"); break;
199 | case 'Q': PlayWav ("queen"); break;
200 | }
201 | }
202 | }
203 |
204 | */
205 |
206 |
207 | /*
208 | $Log: speak.cpp,v $
209 | Revision 1.4 2006/01/18 20:50:08 dcross
210 | The ability to speak move notation through the sound card was broken when
211 | I went from goofy move notation to PGN. This is a quickie hack to make it
212 | work, though it's not perfect because it should say "moves to", and "at", but it doesn't.
213 | Also removed the board and move parameters to Speak(), because they were never used.
214 |
215 | Revision 1.3 2005/11/23 21:30:31 dcross
216 | Removed all references to intersrv.com, because that ISP no longer exists!
217 | Changed references to Chenard web site and my email address to cosinekitty.com.
218 | (Still need to fix cosinekitty.com/chenard.html.)
219 |
220 | Revision 1.2 2005/11/23 21:14:43 dcross
221 | 1. Added cvs log tag at end of each source file.
222 | 2. Moved old manual revision history after cvs log tag.
223 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
224 |
225 |
226 | Revision history:
227 |
228 | 1997 February 1 [Don Cross]
229 | Started writing.
230 |
231 | */
232 |
233 |
--------------------------------------------------------------------------------
/src/stdtime.cpp:
--------------------------------------------------------------------------------
1 | /*=======================================================================
2 |
3 | stdtime.cpp - Copyright (C) 1993-1996 by Don Cross
4 | email: dcross@intersrv.com
5 | WWW: http://www.intersrv.com/~dcross/
6 |
7 | Portable (but horrible granularity) ChessTime() implementation.
8 |
9 | =======================================================================*/
10 |
11 | #include
12 | #include "chess.h"
13 |
14 | INT32 ProgStartTime = 0;
15 |
16 | INT32 ChessTime()
17 | {
18 | return (INT32(time(0)) - ProgStartTime) * INT32(100);
19 | }
20 |
21 |
22 | class StdChessTimeInit
23 | {
24 | public:
25 | StdChessTimeInit()
26 | {
27 | ProgStartTime = time(0);
28 | }
29 | };
30 |
31 |
32 | static StdChessTimeInit KrankyKitty;
33 |
34 | /*
35 | $Log: stdtime.cpp,v $
36 | Revision 1.1 2005/11/25 19:47:27 dcross
37 | Recovered lots of old chess source files from the dead!
38 | Found these on CDROM marked "14 September 1999".
39 | Added cvs log tag and moved old revision history after that.
40 |
41 | */
42 |
43 |
--------------------------------------------------------------------------------
/src/taggit:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ctags --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ *.cpp *.h
3 |
--------------------------------------------------------------------------------
/src/textundo.cpp:
--------------------------------------------------------------------------------
1 | /*=============================================================================
2 |
3 | textundo.cpp - Copyright (C) 1998-2005 by Don Cross
4 |
5 | =============================================================================*/
6 |
7 | #include
8 |
9 | #include "chess.h"
10 | #include "uistdio.h"
11 |
12 | MoveUndoPath Global_MoveUndoPath;
13 |
14 | MoveUndoPath::~MoveUndoPath()
15 | {
16 | if ( moveList )
17 | {
18 | delete[] moveList;
19 | moveList = 0;
20 | current = length = size = 0;
21 | }
22 | }
23 |
24 |
25 | void MoveUndoPath::resetFromBoard ( const ChessBoard &board )
26 | {
27 | current = length = board.GetCurrentPlyNumber();
28 |
29 | if (!moveList || (size < length))
30 | {
31 | if (length < 1024)
32 | {
33 | size = 1024; // arbitrary but larger than necessary
34 | }
35 | else
36 | {
37 | size = 2 * length; // unexpected, but stay ahead of large size
38 | }
39 |
40 | delete[] moveList;
41 | moveList = new Move[size];
42 | }
43 |
44 | for (int i = 0; i < length; i++)
45 | {
46 | moveList[i] = board.GetPastMove(i);
47 | }
48 | }
49 |
50 |
51 | bool MoveUndoPath::undo ( ChessBoard &board )
52 | {
53 | // Allow undo only if board has not been edited
54 | if ( board.HasBeenEdited() )
55 | {
56 | printf ( "!!! Cannot undo move because board has been edited!\n" );
57 | return false;
58 | }
59 |
60 | if ( current < 2 )
61 | {
62 | printf ( "!!! Cannot undo this early in the game!\n" );
63 | return false;
64 | }
65 |
66 | board.Init();
67 | current -= 2;
68 | UnmoveInfo unmove;
69 | for ( int i=0; i length )
86 | {
87 | printf ( "!!! At end of redo list!\n" );
88 | return false;
89 | }
90 |
91 | UnmoveInfo unmove;
92 | board.MakeMove ( moveList[current], unmove );
93 | board.MakeMove ( moveList[current+1], unmove );
94 | current += 2;
95 |
96 | return true;
97 | }
98 |
99 |
100 | /*
101 | $Log: textundo.cpp,v $
102 | Revision 1.4 2006/01/18 19:58:13 dcross
103 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
104 | Now use C++ standard bool, true, false (none of which existed when I started this project).
105 |
106 | Revision 1.3 2005/11/23 21:30:31 dcross
107 | Removed all references to intersrv.com, because that ISP no longer exists!
108 | Changed references to Chenard web site and my email address to cosinekitty.com.
109 | (Still need to fix cosinekitty.com/chenard.html.)
110 |
111 | Revision 1.2 2005/11/23 21:14:43 dcross
112 | 1. Added cvs log tag at end of each source file.
113 | 2. Moved old manual revision history after cvs log tag.
114 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
115 |
116 |
117 | Revision history:
118 |
119 | 1999 January 16 [Don Cross]
120 | Split off from file 'undopath.cpp' for text-mode version
121 | of Chenard.
122 |
123 | 1997 January 30 [Don Cross]
124 | Started writing.
125 |
126 | */
127 |
128 |
--------------------------------------------------------------------------------
/src/ui.cpp:
--------------------------------------------------------------------------------
1 | /*==========================================================================
2 |
3 | ui.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | Contains abstract class ChessUI.
6 |
7 | ==========================================================================*/
8 |
9 | #include "chess.h"
10 |
11 |
12 | ChessUI::ChessUI()
13 | {
14 | }
15 |
16 |
17 | ChessUI::~ChessUI()
18 | {
19 | }
20 |
21 |
22 | void ChessUI::DisplayBestMoveSoFar ( const ChessBoard &, Move, int )
23 | {
24 | }
25 |
26 |
27 | void ChessUI::DisplayCurrentMove ( const ChessBoard &, Move, int )
28 | {
29 | }
30 |
31 |
32 | void ChessUI::PredictMate ( int )
33 | {
34 | }
35 |
36 |
37 | void ChessUI::ReportComputerStats (
38 | INT32, UINT32, UINT32, UINT32,
39 | int, UINT32[NODES_ARRAY_SIZE],
40 | UINT32[NODES_ARRAY_SIZE] )
41 | {
42 | }
43 |
44 |
45 | /*
46 | $Log: ui.cpp,v $
47 | Revision 1.3 2005/11/23 21:30:31 dcross
48 | Removed all references to intersrv.com, because that ISP no longer exists!
49 | Changed references to Chenard web site and my email address to cosinekitty.com.
50 | (Still need to fix cosinekitty.com/chenard.html.)
51 |
52 | Revision 1.2 2005/11/23 21:14:43 dcross
53 | 1. Added cvs log tag at end of each source file.
54 | 2. Moved old manual revision history after cvs log tag.
55 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
56 |
57 |
58 | Revision history:
59 |
60 | 1999 January 5 [Don Cross]
61 | Updating coding style.
62 |
63 | */
64 |
--------------------------------------------------------------------------------
/src/uistdio.h:
--------------------------------------------------------------------------------
1 | /*============================================================================
2 |
3 | uistdio.h - Copyright (C) 1993-2005 by Don Cross
4 |
5 | This is a portable user interface class for my new chess code.
6 |
7 | ============================================================================*/
8 |
9 | #define CHENARD_RELEASE 1
10 |
11 | #ifdef __GNUG__
12 | // [23 November 2005] Don says: I had to turn this off, because I lost the file lichess.h !!!
13 | //#define SUPPORT_LINUX_INTERNET 1
14 | #define SUPPORT_LINUX_INTERNET 0
15 | #else
16 | #define SUPPORT_LINUX_INTERNET 0
17 | #endif
18 |
19 |
20 | enum BoardDisplayType
21 | {
22 | BDT_STANDARD, // original, small board (no color, no frills)
23 | BDT_LARGE_COLOR // uses ANSI terminal color escape sequences
24 | };
25 |
26 |
27 | enum PLAYER_TYPE
28 | {
29 | PT_UNKNOWN,
30 | PT_HUMAN,
31 | PT_COMPUTER,
32 | PT_INTERNET
33 | };
34 |
35 |
36 | BoardDisplayType Next ( BoardDisplayType ); // allows to cycle through all
37 |
38 |
39 | class ChessUI_stdio: public ChessUI
40 | {
41 | public:
42 | ChessUI_stdio();
43 | ~ChessUI_stdio();
44 |
45 | ChessPlayer *CreatePlayer ( ChessSide );
46 | bool ReadMove ( ChessBoard &, int &source, int &dest, SQUARE &promIndex );
47 | SQUARE PromotePawn ( int PawnSource, int PawnDest, ChessSide );
48 | void DisplayMove ( ChessBoard &, Move );
49 | void RecordMove ( ChessBoard &, Move, INT32 thinkTime );
50 | void DrawBoard ( const ChessBoard & );
51 | void ReportEndOfGame ( ChessSide winner );
52 | void DisplayBestMoveSoFar ( const ChessBoard &, Move, int level );
53 | void DisplayCurrentMove ( const ChessBoard &, Move, int level );
54 | void DisplayBestPath ( const ChessBoard &, const BestPath & );
55 | void PredictMate ( int numMoves );
56 |
57 | void Resign ( ChessSide, QuitGameReason ) {}
58 | void NotifyUser ( const char *message );
59 |
60 | void ReportComputerStats ( INT32 thinkTime,
61 | UINT32 nodesVisited,
62 | UINT32 nodesEvaluated,
63 | UINT32 nodesGenerated,
64 | int fwSearchDepth,
65 | UINT32 vis [NODES_ARRAY_SIZE],
66 | UINT32 gen [NODES_ARRAY_SIZE] );
67 |
68 | virtual void ReportSpecial ( const char *msg );
69 | void SetScoreDisplay ( bool _showScores )
70 | {
71 | showScores = _showScores;
72 | }
73 |
74 | bool QueryScoreDisplay () const
75 | {
76 | return showScores;
77 | }
78 |
79 | void EnableCombatMode(ChessSide computerSide);
80 |
81 | private:
82 | void ClearScreen();
83 | void DrawBoard_Standard ( const ChessBoard & );
84 | void DrawBoard_LargeColor ( const ChessBoard & );
85 | Move ConvertStringToMove ( const ChessBoard &,
86 | const char from_to [4] );
87 |
88 | PLAYER_TYPE whitePlayerType;
89 | PLAYER_TYPE blackPlayerType;
90 |
91 | bool showScores; // should UI show moves' min-max scores?
92 | bool rotateBoard; // should board be shown opposite of "sensible" way?
93 | bool beepFlag; // should beep when it is human's turn?
94 |
95 | int numPlayersCreated;
96 |
97 | ChessPlayer *whitePlayer;
98 | ChessPlayer *blackPlayer;
99 | BoardDisplayType boardDisplayType;
100 |
101 | ChessSide combatModeComputerSide; // if not SIDE_NEITHER, determines automatic assignment of computer-vs-human
102 | };
103 |
104 |
105 | class MoveUndoPath
106 | {
107 | public:
108 | MoveUndoPath ():
109 | size(0),
110 | moveList(0),
111 | current(0),
112 | length(0)
113 | {}
114 | ~MoveUndoPath();
115 | void resetFromBoard ( const ChessBoard & );
116 | bool undo ( ChessBoard & );
117 | bool redo ( ChessBoard & );
118 |
119 | private:
120 | int size;
121 | Move *moveList; // dynamically allocated array of 'size'
122 | int current; // index of current position in undo path
123 | int length; // current total length of path
124 | };
125 |
126 | extern MoveUndoPath Global_MoveUndoPath;
127 |
128 |
129 | /*
130 | $Log: uistdio.h,v $
131 | Revision 1.6 2008/11/06 22:25:06 Don.Cross
132 | Now ParseFancyMove accepts either PGN or longmove (e7e8q) style notation only.
133 | We tolerate of check '+' or checkmate '#' characters being absent or extraneous in the input.
134 | The former is especially important because I often see PGN notation where '+' is missing on checking moves.
135 | To allow for PGN input, I had to allow avoidance of the PromotePawn callback, so other code was changed as well.
136 | Version numbers are now always constently yyyy.mm.dd across all builds of Chenard!
137 |
138 | Revision 1.5 2006/01/18 19:58:15 dcross
139 | I finally got around to scrubbing out silly cBOOLEAN, cFALSE, and cTRUE.
140 | Now use C++ standard bool, true, false (none of which existed when I started this project).
141 |
142 | Revision 1.4 2005/11/23 22:52:55 dcross
143 | Ported stdio version of Chenard to SUSE Linux:
144 | 1. Needed #include in chenga.cpp.
145 | 2. Needed temporary Move object in InsertPrediction in search.cpp, because function takes Move &.
146 | 3. Have to turn SUPPORT_LINUX_INTERNET off for the time being, because I lost lichess.h, dang it!
147 |
148 | Revision 1.3 2005/11/23 21:30:31 dcross
149 | Removed all references to intersrv.com, because that ISP no longer exists!
150 | Changed references to Chenard web site and my email address to cosinekitty.com.
151 | (Still need to fix cosinekitty.com/chenard.html.)
152 |
153 | Revision 1.2 2005/11/23 21:14:44 dcross
154 | 1. Added cvs log tag at end of each source file.
155 | 2. Moved old manual revision history after cvs log tag.
156 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
157 |
158 |
159 |
160 | Revision history:
161 |
162 | 1999 January 23 [Don Cross]
163 | Adding support for InternetChessPlayer.
164 |
165 | 1999 January 16 [Don Cross]
166 | Cloning Win32 GUI Chenard's MoveUndoPath data structure so
167 | that text-mode version of Chenard can also undo moves.
168 |
169 | 1999 January 15 [Don Cross]
170 | Modified prototype for ChessUI_stdio::Resign member function
171 | due to changes in chess.h
172 |
173 | */
174 |
175 |
--------------------------------------------------------------------------------
/src/undopath.cpp:
--------------------------------------------------------------------------------
1 | /*=============================================================================
2 |
3 | undopath.cpp - Copyright (C) 1998-2005 by Don Cross
4 |
5 | =============================================================================*/
6 |
7 | #include "chess.h"
8 | #include "winchess.h"
9 | #include "winguich.h"
10 |
11 | MoveUndoPath Global_MoveUndoPath;
12 |
13 | MoveUndoPath::~MoveUndoPath()
14 | {
15 | if ( moveList )
16 | {
17 | delete[] moveList;
18 | moveList = 0;
19 | current = length = size = 0;
20 | }
21 | }
22 |
23 |
24 | void MoveUndoPath::resetFromBoard ( const ChessBoard &board )
25 | {
26 | int initial = board.InitialPlyNumber();
27 | current = length = board.GetCurrentPlyNumber() - initial;
28 |
29 | if ( !moveList )
30 | {
31 | size = 1024; // arbitrary but larger than necessary
32 | if (size < length)
33 | {
34 | size = 2 * length;
35 | }
36 |
37 | moveList = new Move [size];
38 | }
39 |
40 | for (int i = 0; i < length; i++)
41 | {
42 | moveList[i] = board.GetPastMove (i + initial);
43 | }
44 | }
45 |
46 |
47 | void MoveUndoPath::undo ( ChessBoard &board )
48 | {
49 | // Allow undo only if board has not been edited
50 | if ( board.HasBeenEdited() )
51 | {
52 | if ( Global_UI )
53 | {
54 | //TODO: Display error dialog box
55 | }
56 | return;
57 | }
58 |
59 | if ( current < 2 )
60 | {
61 | if ( Global_UI )
62 | {
63 | //TODO: Display error dialog box
64 | }
65 | return;
66 | }
67 |
68 | board.Init();
69 | current -= 2;
70 | UnmoveInfo unmove;
71 | for ( int i=0; i length )
91 | {
92 | return;
93 | }
94 |
95 | UnmoveInfo unmove;
96 | board.MakeMove ( moveList[current], unmove );
97 | board.MakeMove ( moveList[current+1], unmove );
98 | current += 2;
99 | }
100 |
101 |
102 | /*
103 | $Log: undopath.cpp,v $
104 | Revision 1.4 2008/11/13 15:29:05 Don.Cross
105 | Fixed bug: user can now Undo/Redo moves after loading a game from a PGN file.
106 |
107 | Revision 1.3 2005/11/23 21:30:32 dcross
108 | Removed all references to intersrv.com, because that ISP no longer exists!
109 | Changed references to Chenard web site and my email address to cosinekitty.com.
110 | (Still need to fix cosinekitty.com/chenard.html.)
111 |
112 | Revision 1.2 2005/11/23 21:14:44 dcross
113 | 1. Added cvs log tag at end of each source file.
114 | 2. Moved old manual revision history after cvs log tag.
115 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
116 |
117 |
118 | Revision history:
119 |
120 | 1997 January 30 [Don Cross]
121 | Started writing.
122 |
123 | */
124 |
125 |
--------------------------------------------------------------------------------
/src/winchess.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 1993-2008 by Don Cross. All Rights Reserved.
3 |
4 | winchess.h - Resource file identifiers for Win32 GUI version of Chenard
5 | */
6 |
7 | #include
8 |
9 | #define CHENARD_ICON 1
10 | #define DR_CHENARD_ICON 1
11 | #define IDD_EDIT_SQUARE 102
12 | #define DDC_MENU_RESOURCE 1
13 | #define CB_RESTORE_GAME 522
14 | #define RB_W_IS_SECONDS 118
15 | #define RB_W_IS_PLIES 119
16 | #define RB_B_IS_SECONDS 120
17 | #define RB_B_IS_PLIES 121
18 | #define TB_WBIAS 415
19 | #define TB_BBIAS 414
20 | #define CB_ENABLE_SOUNDS 513
21 | #define IDD_DEFINE_PLAYERS 100
22 | #define RB_WHUMAN 103
23 | #define RB_WINTERNET 104
24 | #define RB_WCOMPUTER 105
25 | #define TB_WTIME 412
26 | #define TB_BTIME 409
27 | #define RB_BHUMAN 106
28 | #define RB_BINTERNET 107
29 | #define RB_BCOMPUTER 108
30 | #define RB_W_NAMEDPIPE 109
31 | #define RB_B_NAMEDPIPE 110
32 | #define TB_EDIT_FEN 600
33 |
34 | #define IDD_PROMOTE_PAWN 101
35 | #define RB_QUEEN 201
36 | #define RB_ROOK 202
37 | #define RB_BISHOP 203
38 | #define RB_KNIGHT 204
39 |
40 | #define IDC_LOAD_FILENAME 301
41 |
42 | #define IDD_REQUEST_SUGGESTION 167
43 | #define IDD_DEFINE_PLAYERS2 168
44 | #define IDD_EDIT_THINK_TIMES 169
45 | #define IDD_ABOUT 170
46 | #define IDD_ENTER_FEN 171
47 | #define IDD_EDIT_BLUNDER_THRESHOLD 172
48 |
49 | #define IDR_ACCELERATOR1 400
50 |
51 | /*
52 | $Log: winchess.h,v $
53 | Revision 1.5 2008/11/17 18:47:07 Don.Cross
54 | WinChen.exe now has an Edit/Enter FEN function for setting a board position based on a FEN string.
55 | Tweaked ChessBoard::SetForsythEdwardsNotation to skip over any leading white space.
56 | Fixed incorrect Chenard web site URL in the about box.
57 | Now that computers are so much faster, reduced the
58 |
59 | Revision 1.4 2006/02/25 22:22:19 dcross
60 | Added support for connecting to Flywheel named pipe server as a Chenard chess player.
61 | This allows me to use my new Flywheel engine via the Chenard GUI.
62 |
63 | Revision 1.3 2005/11/23 21:30:32 dcross
64 | Removed all references to intersrv.com, because that ISP no longer exists!
65 | Changed references to Chenard web site and my email address to cosinekitty.com.
66 | (Still need to fix cosinekitty.com/chenard.html.)
67 |
68 | Revision 1.2 2005/11/23 21:14:44 dcross
69 | 1. Added cvs log tag at end of each source file.
70 | 2. Moved old manual revision history after cvs log tag.
71 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
72 |
73 | */
74 |
75 |
--------------------------------------------------------------------------------
/src/wintime.cpp:
--------------------------------------------------------------------------------
1 | /*=========================================================================
2 |
3 | wintime.cpp - Copyright (C) 1993-2005 by Don Cross
4 |
5 | Win32 version of ChessTime. This function returns a
6 | time value expressed in hundredths of a second.
7 | The most important use of this function is to enable
8 | a timed search to know when to stop.
9 |
10 | =========================================================================*/
11 |
12 | #include
13 |
14 | #include "chess.h"
15 |
16 | INT32 ChessTime()
17 | {
18 | static bool firstTime = true;
19 | static LARGE_INTEGER startTime;
20 | static LARGE_INTEGER performanceFrequency;
21 |
22 | LARGE_INTEGER pc;
23 | if (!QueryPerformanceCounter (&pc))
24 | {
25 | ChessFatal ("Failure in QueryPerformanceCounter()");
26 | }
27 |
28 | if (firstTime)
29 | {
30 | startTime = pc;
31 | firstTime = false;
32 |
33 | if (!QueryPerformanceFrequency (&performanceFrequency))
34 | {
35 | ChessFatal ("Failure in QueryPerformanceFrequency");
36 | }
37 |
38 | if (performanceFrequency.QuadPart <= 1000)
39 | {
40 | ChessFatal ("QueryPerformanceFrequency returned a value that is too small!");
41 | }
42 |
43 | performanceFrequency.QuadPart /= 100; // instead of counts per second, we want counts per centisecond!
44 |
45 | return 0;
46 | }
47 | else
48 | {
49 | // WARNING: This code can go 248.5513 days before wraping around the signed 32-bit integer.
50 | // That should be good enough for most uses, but it could cause problems some day.
51 | // If so, I will need to redesign ChessTime() to return a 64-bit integer.
52 |
53 | __int64 diff = pc.QuadPart - startTime.QuadPart;
54 | diff /= performanceFrequency.QuadPart;
55 | return (INT32) diff;
56 | }
57 | }
58 |
59 |
60 | /*
61 | $Log: wintime.cpp,v $
62 | Revision 1.4 2008/11/07 20:56:29 Don.Cross
63 | Reworked wintime.cpp so it uses QueryPerformanceCounter instead of GetTickCount.
64 | The only reason I did this was to increase the time of integer overflow from 49 days to 248 days.
65 |
66 | Revision 1.3 2005/11/23 21:30:33 dcross
67 | Removed all references to intersrv.com, because that ISP no longer exists!
68 | Changed references to Chenard web site and my email address to cosinekitty.com.
69 | (Still need to fix cosinekitty.com/chenard.html.)
70 |
71 | Revision 1.2 2005/11/23 21:14:45 dcross
72 | 1. Added cvs log tag at end of each source file.
73 | 2. Moved old manual revision history after cvs log tag.
74 | 3. Made sure each source file has extra blank line at end so gcc under Linux won't fuss!
75 |
76 |
77 |
78 | Revision history:
79 |
80 | 1999 February 12 [Don Cross]
81 | Updated to call the newer function 'GetTickCount()'.
82 | Also protected against clock wraparound by calculating
83 | all times as differences from the first call.
84 | */
85 |
86 |
--------------------------------------------------------------------------------
/ttychess/ttychess.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ttychess", "ttychess\ttychess.vcxproj", "{FD6A732B-9931-4A3D-A917-03114FC408C2}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {FD6A732B-9931-4A3D-A917-03114FC408C2}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {FD6A732B-9931-4A3D-A917-03114FC408C2}.Debug|Win32.Build.0 = Debug|Win32
14 | {FD6A732B-9931-4A3D-A917-03114FC408C2}.Release|Win32.ActiveCfg = Release|Win32
15 | {FD6A732B-9931-4A3D-A917-03114FC408C2}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/ttychess/ttychess/ttychess.ini:
--------------------------------------------------------------------------------
1 | #
2 | # ttychess.ini - Configuration file for ttychess.exe.
3 | #
4 | SERIAL=1 # set to 1 to enable serial I/O, 0 to disable
5 | PORT=COM8
6 | BAUD=110
7 | ECHO=1 # 1 if you need characters echoed back to TTY, 0 if not.
8 | UPCASE=1 # 1 to force all output to upper case, 0 to allow mixed case
9 | BYTESIZE=8 # number of bits in a byte: 4..8
10 | PARITY=0 # 0=none, 1=odd, 2=even, 3=mark, 4=space
11 | STOPBITS=2 # number of stop bits to send: 0 for 1 bit, 1 for 1.5, 2 for 2
12 | CRDELAY=0 # how many milliseconds to delay after sending a carriage return
--------------------------------------------------------------------------------
/ttychess/ttychess/ttychess.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {FD6A732B-9931-4A3D-A917-03114FC408C2}
15 | Win32Proj
16 | ttychess
17 |
18 |
19 |
20 | Application
21 | true
22 | v110
23 | Unicode
24 |
25 |
26 | Application
27 | false
28 | v110
29 | true
30 | Unicode
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 | true
44 |
45 |
46 | false
47 |
48 |
49 |
50 |
51 |
52 | Level3
53 | Disabled
54 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
55 | $(ProjectDir)..\..\src;%(AdditionalIncludeDirectories)
56 |
57 |
58 | Console
59 | true
60 |
61 |
62 |
63 |
64 | Level3
65 |
66 |
67 | MaxSpeed
68 | true
69 | true
70 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
71 | $(ProjectDir)..\..\src;%(AdditionalIncludeDirectories)
72 |
73 |
74 | Console
75 | true
76 | true
77 | true
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 |
--------------------------------------------------------------------------------
/ttychess/ttychess/ttychess.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files
56 |
57 |
58 | Source Files
59 |
60 |
61 | Source Files
62 |
63 |
64 | Source Files
65 |
66 |
67 | Source Files
68 |
69 |
70 | Source Files
71 |
72 |
73 | Source Files
74 |
75 |
76 | Source Files
77 |
78 |
79 | Source Files
80 |
81 |
82 | Source Files
83 |
84 |
85 | Source Files
86 |
87 |
88 | Source Files
89 |
90 |
91 | Source Files
92 |
93 |
94 | Source Files
95 |
96 |
97 | Source Files
98 |
99 |
100 | Source Files
101 |
102 |
103 | Source Files
104 |
105 |
106 | Source Files
107 |
108 |
109 | Source Files
110 |
111 |
112 | Source Files
113 |
114 |
115 |
116 |
117 | Header Files
118 |
119 |
120 | Header Files
121 |
122 |
123 | Header Files
124 |
125 |
126 | Header Files
127 |
128 |
129 | Header Files
130 |
131 |
132 | Header Files
133 |
134 |
135 | Header Files
136 |
137 |
138 | Header Files
139 |
140 |
141 | Header Files
142 |
143 |
144 |
--------------------------------------------------------------------------------
/winbin/rebuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal EnableDelayedExpansion
3 |
4 | if not exist chenard.sln (
5 | echo ERROR: Cannot find chenard.sln
6 | exit /b 1
7 | )
8 |
9 | if not defined VCINSTALLDIR (
10 | call "c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsamd64_x86.bat"
11 | )
12 |
13 | if not exist logs (
14 | mkdir logs
15 | if not exist logs (
16 | echo ERROR: cannot create 'logs' directory.
17 | exit /b 1
18 | )
19 | echo Created 'logs' directory.
20 | )
21 |
22 | for %%p in (Win32 x64) do (
23 | for %%c in (Debug Release) do (
24 | echo Rebuilding Chenard %%p %%c
25 | > logs\build_%%p_%%c.log msbuild chenard.sln /t:rebuild /p:Platform=%%p /p:Configuration=%%c
26 | if errorlevel 1 (
27 | echo *** BUILD ERROR ***
28 | exit /b 1
29 | )
30 | )
31 | )
32 |
33 | echo Successful rebuild of all Chenard executables.
34 | exit /b 0
35 |
--------------------------------------------------------------------------------
/winchen/winchen.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files
56 |
57 |
58 | Source Files
59 |
60 |
61 | Source Files
62 |
63 |
64 | Source Files
65 |
66 |
67 | Source Files
68 |
69 |
70 | Source Files
71 |
72 |
73 | Source Files
74 |
75 |
76 | Source Files
77 |
78 |
79 | Source Files
80 |
81 |
82 | Source Files
83 |
84 |
85 | Source Files
86 |
87 |
88 | Source Files
89 |
90 |
91 | Source Files
92 |
93 |
94 | Source Files
95 |
96 |
97 | Source Files
98 |
99 |
100 | Source Files
101 |
102 |
103 | Source Files
104 |
105 |
106 | Source Files
107 |
108 |
109 | Source Files
110 |
111 |
112 | Source Files
113 |
114 |
115 | Source Files
116 |
117 |
118 | Source Files
119 |
120 |
121 | Source Files
122 |
123 |
124 |
125 |
126 | Header Files
127 |
128 |
129 | Header Files
130 |
131 |
132 | Header Files
133 |
134 |
135 | Header Files
136 |
137 |
138 | Header Files
139 |
140 |
141 | Header Files
142 |
143 |
144 | Header Files
145 |
146 |
147 | Header Files
148 |
149 |
150 | Header Files
151 |
152 |
153 | Header Files
154 |
155 |
156 | Header Files
157 |
158 |
159 |
160 |
161 | Resource Files
162 |
163 |
164 |
165 |
166 | Resource Files
167 |
168 |
169 |
--------------------------------------------------------------------------------
/xchenard/xchenard.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 | Source Files
35 |
36 |
37 | Source Files
38 |
39 |
40 | Source Files
41 |
42 |
43 | Source Files
44 |
45 |
46 | Source Files
47 |
48 |
49 | Source Files
50 |
51 |
52 | Source Files
53 |
54 |
55 | Source Files
56 |
57 |
58 | Source Files
59 |
60 |
61 | Source Files
62 |
63 |
64 | Source Files
65 |
66 |
67 | Source Files
68 |
69 |
70 | Source Files
71 |
72 |
73 | Source Files
74 |
75 |
76 | Source Files
77 |
78 |
79 | Source Files
80 |
81 |
82 | Source Files
83 |
84 |
85 | Source Files
86 |
87 |
88 | Source Files
89 |
90 |
91 | Source Files
92 |
93 |
94 | Source Files
95 |
96 |
97 | Source Files
98 |
99 |
100 | Source Files
101 |
102 |
103 | Source Files
104 |
105 |
106 | Source Files
107 |
108 |
109 | Source Files
110 |
111 |
112 |
113 |
114 | Header Files
115 |
116 |
117 | Header Files
118 |
119 |
120 | Header Files
121 |
122 |
123 | Header Files
124 |
125 |
126 | Header Files
127 |
128 |
129 |
--------------------------------------------------------------------------------