22#ifndef HODJNPODJ_MANKALA_MNK_H
23#define HODJNPODJ_MANKALA_MNK_H
25#include "common/serializer.h"
26#include "bagel/hodjnpodj/globals.h"
27#include "bagel/hodjnpodj/hnplibs/dibdoc.h"
28#include "bagel/hodjnpodj/hnplibs/sprite.h"
29#include "bagel/hodjnpodj/hnplibs/bitmaps.h"
30#include "bagel/boflib/sound.h"
31#include "bagel/hodjnpodj/mankala/bgen.h"
32#include "bagel/hodjnpodj/mankala/bgenut.h"
33#include "bagel/hodjnpodj/mankala/btimeut.h"
34#include "bagel/hodjnpodj/mankala/mnkopt.h"
35#include "bagel/hodjnpodj/mankala/resource.h"
45#define DATADIR "art\\"
48const int MAXMOVES = 100 ;
49const int NUMPITS = 6 ;
50const int NUMPLAYERS = 2 ;
51const int TOTALPITS = NUMPLAYERS * NUMPITS ;
53const int HANDINDEX = -2, HOMEINDEX = -1 ;
55const int MAXDISPPIT = 8, MAXDISPHOME = 22, MAXDISPHAND = MAXPOSINT ;
61const int MINSTONES = 3, MAXSTONES = 7 ;
62const int MINSTRENGTH = 1, MAXSTRENGTH = 4 ;
65const int MAXTABLESTONES = 12 ;
66const unsigned long MAXCONFIGS = 3000000L ;
69const int BESTWINBITS = 5 ;
70const int TABLEUNDEF = (-16 + 32) ;
71const int BESTWINUNDEF = -1000 ;
77#define BMT_LEFTBIN 203
78#define BMT_RIGHTBIN 204
93#define RULES "mankala.txt"
95#define RULES_NARRATION "sound\\mankala.wav"
96#define IGO3 "sound\\igo3.wav"
97#define YOUGO3 "sound\\yougo3.wav"
98#define GOAGAIN "sound\\goagain.wav"
99#define IGOAGAIN "sound\\igoagain.wav"
100#define PICKUP "sound\\pickup.wav"
101#define ONESHELL "sound\\oneshell.wav"
102#define INK "sound\\ink.wav"
103#define BROCHURE "sound\\brochure.wav"
104#define ARMCHAIR "sound\\armchair.wav"
105#define FISHHOOK "sound\\fishhook.wav"
106#define PAILS "sound\\pails.wav"
107#define NETSHELL "sound\\netshell.wav"
108#define WHEEL "sound\\wheel.wav"
109#define HONK "sound\\honk.wav"
110#define POP "sound\\pop.wav"
111#define INFLATE "sound\\inflate.wav"
112#define SOSORRY "sound\\sosorry.wav"
113#define FANFARE2 "sound\\fanfare2.wav"
114#define MIDI_BCKGND "sound\\mankala.mid"
115#define GLOBE_SPRITE "art\\globe2.bmp"
116#define CHAIR_SPRITE "art\\chair.bmp"
121#define OTHERPLAYER(iPlayer) (NUMPLAYERS - 1 - iPlayer)
122#define MAXRECURSION 3
126 int iFree[NUMPITS][MAXRECURSION];
127 int iCapture[NUMPITS][MAXRECURSION];
129 int iPitSequence[MAXRECURSION];
130 int iNumRocks[NUMPITS];
131 int iNumRocksOpposite[NUMPITS];
132 signed char cRecursion;
145 const char *m_xpszFilenameString;
146 bool m_bSubNumStones;
156 bool m_bChained =
false, m_bHeap =
false;
158 bool m_bDummy =
false;
159 bool m_bMasked =
false;
160 class CPitWnd *m_xpcPit =
nullptr;
161 bool m_bInit =
false;
166 bool m_bSprite =
false;
167 CSprite *m_xpcSprite =
nullptr;
170 HDIB m_lpDib =
nullptr;
180 bool m_bRealMove =
false;
182 int m_iNumStones[NUMPLAYERS][NUMPITS + 2] = {};
184 int m_iTotalStones = 0;
185 long m_lConfigIndex = 0;
186 int m_iValues[NUMPITS] = {};
187 int m_iBestWinValue = 0;
189 class CPit *m_xpcPit =
nullptr;
190 bool m_bFreeTurn =
false;
191 bool m_bCapture =
false;
192 int m_iCapturePit = 0;
193 bool m_bHasCapture =
false;
194 bool m_bHasFree =
false;
200 Common::fill(&m_iNumStones[0][0], &m_iNumStones[0][0] + NUMPLAYERS * (NUMPITS + 2), 0);
211 m_bHasCapture =
false;
215 void Copy(
CMove *xpcMove) {
225 int m_iNumStones = 0, m_iDispStones = 0, m_iDispMax = 0;
226 int m_iPlayer = 0, m_iPit = 0;
236 bool m_bStartGame =
false;
237 bool m_bGameOver =
false;
238 bool m_bGameOverMusicPlayed =
false;
239 int m_iTableStones = 0;
240 long m_lNumConfigs = 0;
241 long m_lTableSize = 0;
242 bool m_bInitData =
false;
243 class CMnkData FAR *m_lpCMnkData =
nullptr;
244 CSound *m_pSound =
nullptr;
248 int m_iStartStones = 0;
249 bool m_bComputer[NUMPLAYERS] = {};
251 class CPit *m_xpcPits[NUMPLAYERS][NUMPITS + 2] = {};
253 int m_iMaxDepth[NUMPLAYERS] = {}, m_iCurrentMaxDepth = 0;
255 int m_iCapDepth[NUMPLAYERS] = {}, m_iCurrentCapDepth = 0;
257 int m_iNumberMoves = 0;
258 class CMove m_cCurrentMove;
259 class CMove m_cMoveList[MAXMOVES];
260 enum enum_Level {LEV_NONE, LEV_RANDOM,
261 LEV_LOWEST, LEV_HIGHEST, LEV_EVAL, LEV_MINIMAX
263 m_eLevel[NUMPLAYERS] = {};
265 bool m_bDumpPopulate =
false,
266 m_bDumpMoves =
false,
274 bool ReadTableFile();
280 bool WriteTableFile();
286private:
bool InitMankala() ;
288private:
bool Move(
CPit * xpcSowPit,
CMove * xpcMove PDFT(
nullptr)) ;
290public:
bool MoveStone(
CMove * xpcMove,
291 CPit * xpcFromPit,
CPit * xpcToPit) ;
293private:
bool InitData(
bool bInit PDFT(
true)) ;
295 bool CountConfigurations() ;
297private:
bool PopulateTable() ;
300 bool MapConfiguration(
CMove * xpcMove) ;
303 bool UnmapConfiguration(
CMove * xpcMove) ;
305private:
bool SearchMove(
CMove * xpcMove,
int &iMove) ;
307 bool Minimax(
CMove * xpcMove,
int iDepth PDFT(0)) ;
309 bool StaticEvaluation(
CMove * xpcMove) ;
311 bool CountStones(
CMove * xpcMove) ;
313private:
bool GetBestWinCount(
CMove * xpcMove) ;
315private:
bool SetBestWinCount(
CMove * xpcMove) ;
317 bool DumpPosition(
CMove * xpcMove) ;
319 bool DumpBestWinTable(
long lLow PDFT(0),
320 long lHigh PDFT(6 * 24 - 1)) ;
321 bool AggressiveStaticEvaluation(
CMove* xpcMove);
323 bool DefensiveStaticEvaluation(
CMove*);
324 bool TreeAlgo(
CMove*);
347 char m_szText[80] = {};
348 int m_iHeaderSize = 0;
350 int m_iTableStones = 0;
351 long m_lTableSize = 0;
361 long m_NX[MAXTABLESTONES + 1][TOTALPITS + 1] = {},
362 m_NA[MAXTABLESTONES + 1][TOTALPITS + 1] = {};
368 HGLOBAL m_hBestWin =
nullptr;
369 byte *m_hpcBestWin =
nullptr;
375} class_CMnkData, *HPCMNKDATA;
377#define SPRITE_COUNT 15
378#define BUMPER_COUNT 5
379#define SPRITE_TIMER 50
380#define SPRITE_INTERVAL 10
381#define SPRITE_GENERATE 30
388#define QUIT_BUTTON_WIDTH 50
389#define QUIT_BUTTON_HEIGHT 20
390#define QUIT_BUTTON_OFFSET_X 10
391#define QUIT_BUTTON_OFFSET_Y 10
393#define OKAY_BUTTON_WIDTH 63
394#define OKAY_BUTTON_HEIGHT 39
395#define OKAY_BUTTON_OFFSET_X 10
396#define OKAY_BUTTON_OFFSET_Y 10
412 bool bPlayedGameOnce =
false;
414 bool m_bJustStarted =
false;
415 bool m_bGameWon =
false;
416 bool m_bRulesActive =
false;
418 bool m_bScoresDisplayed =
false;
420 CText *m_pText =
nullptr;
423 CPalette *m_xpGamePalette =
nullptr, *m_xpOldPalette =
nullptr;
428 bool m_bInMenu =
false;
429 bool m_bPlaySound =
false;
430 char m_szDataDirectory[100] = {};
436 class CPitWnd *m_xpcPits[NUMPLAYERS][NUMPITS + 2] = {};
455private:
bool StartGame() ;
457private:
bool PaintBitmapObject(
CBmpObject * xpcBmpObject,
458 int iBmpType PDFT(0),
int iBmpArg PDFT(0)) ;
460private:
bool InitBitmapObject(
CBmpObject * xpcBmpObject) ;
462private:
bool InitBitmapFilename(
CBmpObject * xpcBmpObject) ;
464private:
bool SetBitmapCoordinates(
467 bool AcceptClick(
CPoint cClickPoint) ;
469public:
bool MoveStoneDisplay(
CPitWnd * xpcFromPit,
473private:
bool AdjustPitDisplay(
CPitWnd * xpcPit,
474 bool bForcePaint PDFT(
false)) ;
476private:
void PaintScreen() ;
478private:
bool ProcessDc(
bool bAlloc PDFT(
true)) ;
480 bool AllocatePits() ;
482private:
bool SetCrabSign(
bool bPaint PDFT(
true)) ;
485private:
bool FreePitResources(
bool bDelete PDFT(
false)) ;
487private:
bool ClearBitmapObject(
CBmpObject * xpcBmpObject) ;
489public:
void ReleaseResources() ;
491private:
bool DebugDialog() ;
492public:
void Setm_bJustStarted(
bool U) {
495public:
bool FAR PASCAL UserDialog() ;
497private:
bool OptionsDialog() ;
518 virtual bool OnCommand(WPARAM wParam, LPARAM lParam)
override;
519 virtual LRESULT OnMCINotify(WPARAM W, LPARAM L);
520 virtual LRESULT OnMMIONotify(WPARAM W, LPARAM L);
523 afx_msg
void OnPaint();
524 afx_msg
void OnLButtonDown(
unsigned int,
CPoint);
525 afx_msg
void OnLButtonUp(
unsigned int,
CPoint);
526 afx_msg
void OnLButtonDblClk(
unsigned int,
CPoint);
527 afx_msg
void OnMButtonDown(
unsigned int,
CPoint);
528 afx_msg
void OnMButtonUp(
unsigned int,
CPoint);
529 afx_msg
void OnMButtonDblClk(
unsigned int,
CPoint);
530 afx_msg
void OnRButtonDown(
unsigned int,
CPoint);
531 afx_msg
void OnRButtonUp(
unsigned int,
CPoint);
532 afx_msg
void OnRButtonDblClk(
unsigned int,
CPoint);
533 afx_msg
void OnMouseMove(
unsigned int nFlags,
CPoint point);
534 afx_msg
void OnChar(
unsigned int nChar,
unsigned int nRepCnt,
unsigned int nFlags);
535 afx_msg
void OnSysChar(
unsigned int nChar,
unsigned int nRepCnt,
unsigned int nFlags);
536 afx_msg
void OnTimer(uintptr nIDEvent);
537 afx_msg
void OnClose();
538 afx_msg
void OnKeyDown(
unsigned int nChar,
unsigned int nRepCnt,
unsigned int nFlags);
539 afx_msg
void OnSysKeyDown(
unsigned int nChar,
unsigned int nRepCnt,
unsigned int nFlags);
542 DECLARE_MESSAGE_MAP()
Definition: serializer.h:80
Definition: afxwin.h:1532
Definition: atltypes.h:79
Definition: atltypes.h:131
Definition: atltypes.h:40
Definition: afxwin.h:1966
Definition: managed_surface.h:51
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168