Add Checkers to AUTOBUILD

git-svn-id: svn://kolibrios.org@4652 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
ashmew2
2014-03-15 16:34:45 +00:00
parent 37230b0b5a
commit 7156671f0b
5 changed files with 167 additions and 100 deletions

View File

@@ -624,6 +624,24 @@ e80: .obj.e80/start.o .obj.e80/kolibri.o .obj.e80/stdlib.o .obj.e80/string.o .ob
.obj.e80:
mkdir -p .obj.e80
# Rules for Checkers
CHECKERSDIR=$(PROGS)/games/checkers/trunk
checkers : $(CHECKERSDIR)/checkers.o
g++ -L/usr/X11R6/lib -lX11 -o checkers checkers.o
$(CHECKERSDIR)/checkers.o : $(CHECKERSDIR)/checkers.cpp \
$(CHECKERSDIR)/position.h \
$(CHECKERSDIR)/board.h \
$(CHECKERSDIR)/player.h \
$(CHECKERSDIR)/tmplayer.h \
$(CHECKERSDIR)/buttons.h \
$(CHECKERSDIR)/history.h \
$(CHECKERSDIR)/hash.h \
$(CHECKERSDIR)/gr-draw.h \
$(CHECKERSDIR)/gnu-draw.h \
$(CHECKERSDIR)/sysproc.h
g++ -c $(CHECKERSDIR)/checkers.cpp
# Rules for sdk/sound, used by media/ac97snd
SOUNDDIR=$(PROGS)/develop/sdk/trunk/sound/src
SOUND_OBJECTS:=$(patsubst $(SOUNDDIR)/%.asm,.sdk/%.obj,$(wildcard $(SOUNDDIR)/*.asm))

View File

@@ -1,4 +1,8 @@
#define BUILD_RUS
#ifndef AUTOBUILD
#include "lang.h"
#endif
@@ -291,10 +295,73 @@ protected:
static int ReadFileTo(FILE *f, char c);
static int ReadFileTo(FILE *f, const char *c);
static int ReadTheText(FILE *f, const char *s);
#endif
};
#ifndef __MENUET__
#if LANG_RUS //Pending Russian Translations
#define CHECKERS_CANT_OPEN_STR "\n<><6E>誨: <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><> \"%s\".\n"
#define CHECKERS_FILE_EMPTY_STR "\n<><6E>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD>.\n"
#define CHECKERS_INVALID_FILE_STR "\n<><6E>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><EFBFBD><E8A8A1><EFBFBD><EFBFBD><EFBFBD>.\n"
#define FILE_WRONG_TYPE_STR "\n<><6E>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> .\n"
#define ERROR_OPENING_FILE_STR "\n<><6E>誨: <20><EFBFBD><E8A8A1> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><E4A0A9> \"%s\".\n"
#define FILE_HAS_NO_GAMES_STR "\n<><6E>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><><EFBFBD> <20><><EFBFBD>.\n"
#define CANT_OPEN_FILE_STR "\n<><6E>誨: <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><> \"%s\" <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n"
#define CHECKERS_STR "<22><>誨"
#define FILE_SAVED_STR "\n<><6E>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD><E0A0AD>.\n"
#define ERROR_SAVING_FILE_STR "\n<><6E>誨: <20><EFBFBD><E8A8A1> <20><><EFBFBD><EFBFBD><E0A0AD><EFBFBD><EFBFBD><><E4A0A9> \"%s\".\n"
#define NOT_ENOUGH_MEM_STR "\n<><6E>誨: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><E0A0AD><EFBFBD><EFBFBD><><E4A0A9> \"%s\".\n"
#define KIND_EQ2 "kind = 2\n"
#define END_STR "[end]"
#define PLAYV11_STR "[play_v1.1]"
#define CHECKERS_PLAY_STR "checkers-play:text\n"
#define CHECKERS_BIN_STR "checkers-play:bin_1.0\n"
#define BLUE_STR "blue: "
#define RED_STR "red: "
#define INPUT_STR "input"
#define COMPUTER_STR "computer"
#define NEW_GAME_STR "new game"
#define LIST_STR "list"
#define DELETE_STR "delete"
#define CLEAR_STR "clear"
#define SAVE_STR "save"
#define ROTATE_BOARD_STR "rotate board"
#define EXIT_STR "exit"
#define CHECKERS_INVALID_STR "Checkers: Invalid key %s\n"
const char *const TPlayArray::search[] =
{"checkers-", "play:", "text", "bin_1.0\n", "history_", "1.0", "1.1"};
#else /*For all other languages except RUS*/
#define CHECKERS_CANT_OPEN_STR "\nCheckers: Can't open the file \"%s\".\n"
#define CHECKERS_FILE_EMPTY_STR "\nCheckers: The file \"%s\" is empty.\n"
#define CHECKERS_INVALID_FILE_STR "\nCheckers: Invalid file \"%s\".\n"
#define FILE_WRONG_TYPE_STR "\nCheckers: The file \"%s\" has the wrong type.\n"
#define ERROR_OPENING_FILE_STR "\nCheckers: Error opening the file \"%s\".\n"
#define FILE_HAS_NO_GAMES_STR "\nCheckers: File \"%s\" doesn't contain games.\n"
#define CANT_OPEN_FILE_STR "\nCheckers: Can't open the file \"%s\" to write.\n"
#define NOT_ENOUGH_MEM_STR "\nCheckers: Not enough memory to save the file \"%s\".\n"
#define ERROR_SAVING_FILE_STR "\nCheckers: Error saving the file \"%s\".\n"
#define FILE_SAVED_STR "\nCheckers: File \"%s\" saved.\n"
#define CHECKERS_STR "Checkers"
#define KIND_EQ2 "kind = 2\n"
#define END_STR "[end]"
#define PLAYV11_STR "[Play_v1.1]"
#define CHECKERS_PLAY_STR "checkers-play:text\n"
#define CHECKERS_BIN_STR "checkers-play:bin_1.0\n"
#define BLUE_STR "blue: "
#define RED_STR "red: "
#define INPUT_STR "input"
#define COMPUTER_STR "computer"
#define NEW_GAME_STR "new game"
#define LIST_STR "list"
#define DELETE_STR "delete"
#define CLEAR_STR "clear"
#define SAVE_STR "save"
#define ROTATE_BOARD_STR "rotate board"
#endif
#define EXIT_STR "exit"
#define CHECKERS_INVALID_STR "Checkers: Invalid key %s\n"
const char *const TPlayArray::search[] =
{"checkers-", "play:", "text", "bin_1.0\n", "history_", "1.0", "1.1"};
#endif
@@ -455,7 +522,7 @@ int TPlayArray::OpenFile(const char *name, int kind)
}
if (pl) delete[] pl;
fclose(f);
printf("kind = 2\n");
return 1;
}
if (kind == 2)
{
@@ -472,7 +539,7 @@ int TPlayArray::OpenFile(const char *name, int kind)
for (;;)
{
do
if (feof(f)) strcpy(word, "[end]");
{
if (fread(&ch, 1, 1, f) != 1) break;
}
while(ch == 0 || isspace(ch));
@@ -516,6 +583,9 @@ int TPlayArray::OpenFile(const char *name, int kind)
else if (pl.Add(pmv.mv) != 0) kind = 3;
}
}
}
}
else
{
char end_literal[] = END_STR;
char playv11_literal[] = PLAYV11_STR;
@@ -526,8 +596,8 @@ int TPlayArray::OpenFile(const char *name, int kind)
pl.Clear();
}
kind = 0;
if (strskipref(word, "[end]")) break;
else if (strskipref(word, "[play_v1.1]")) kind = 1;
for (i = 0; word[i]; i++)
{
word[i] = (char)tolower((unsigned char)word[i]);
}
if (strskipref(word, end_literal)) break;
@@ -588,59 +658,35 @@ int TPlayArray::MsgOpenFile(const char *name, int kind)
{
int n0 = nplay, no_games = 0;
int r = OpenFile(name, kind);
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><> \"%s\".\n", name);
#else
printf("\nCheckers: Can't open the file \"%s\".\n", name);
#endif
if (r <= 0)
{
if (r == -1)
{
printf(CHECKERS_CANT_OPEN_STR, name);
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD>.\n", name);
#else
printf("\nCheckers: The file \"%s\" is empty.\n", name);
#endif
return 0;
}
else if (r == -2)
{
printf(CHECKERS_FILE_EMPTY_STR, name);
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><EFBFBD><E8A8A1><EFBFBD><EFBFBD><EFBFBD>.\n", name);
#else
printf("\nCheckers: Invalid file \"%s\".\n", name);
#endif
return 0;
}
else if (r == -3)
{
printf(CHECKERS_INVALID_FILE_STR, name);
return 0;
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> .\n", name);
#else
printf("\nCheckers: The file \"%s\" has wrong type.\n", name);
#endif
}
else if (r == -4) no_games = 1;
else if (r == -10)
{
printf(FILE_WRONG_TYPE_STR, name);
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><EFBFBD><E8A8A1> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><E4A0A9> \"%s\".\n", name);
#else
printf("\nCheckers: Error openning the file \"%s\".\n", name);
#endif
return 0;
}
else
{
printf(ERROR_OPENING_FILE_STR, name);
return 0;
}
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><><EFBFBD> <20><><EFBFBD>.\n", name);
#else
printf("\nCheckers: File \"%s\" don't contains games.\n", name);
#endif
}
if (!no_games && nplay > n0) return 1;
else
{
@@ -652,7 +698,8 @@ int TPlayArray::SaveFile(const char *name, int num, int kind)
int TPlayArray::SaveFile(const char *name, int num, int kind)
{
FILE *f = 0;
fprintf(f, "checkers-play:text\n");
if (kind == 0 || kind == 1 || kind == 2)
{
f = fopen(name, "wt");
if (!f) return -1;
@@ -662,7 +709,7 @@ int TPlayArray::SaveFile(const char *name, int num, int kind)
for (i = i0; i <= num; i++) if (play[i].GetN() > 0)
{
PlayWrite::PMv pmv;
fprintf(f, "\n[Play_v1.1]#%d %s\n", i - i0 + 1, str);
if (play[i].GetPos(pmv.pos, 0) < 0) return -9;
char *str = new char[10 + NUM_CELL];
if (!str) return -5;
pmv.pos.Write(str, 1);
@@ -690,7 +737,8 @@ int TPlayArray::SaveFile(const char *name, int num, int kind)
fclose(f);
return 1;
}
if (kind == 3) fprintf(f, "checkers-play:bin_1.0\n");
else if (kind == -1 || kind == 3)
{
f = fopen(name, "wb");
if (!f) return -1;
if (kind == 3) fprintf(f, CHECKERS_BIN_STR);
@@ -728,45 +776,25 @@ int TPlayArray::MsgSaveFile(const char *name, int num, int kind)
int TPlayArray::MsgSaveFile(const char *name, int num, int kind)
{
int r = SaveFile(name, num, kind);
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><> \"%s\" <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.\n", name);
#else
printf("\nCheckers: Can't open the file \"%s\" to write.\n", name);
#endif
if (r <= 0)
{
if (r == -1)
{
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><E0A0AD><EFBFBD><EFBFBD><><E4A0A9> \"%s\".\n", name);
#else
printf("\nCheckers: Not enough memory to save the file \"%s\".\n", name);
#endif
printf(CANT_OPEN_FILE_STR, name);
}
else if (r == -5)
{
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> .\n", name);
#else
printf("\nCheckers: The file \"%s\" has wrong type.\n", name);
#endif
printf(NOT_ENOUGH_MEM_STR, name);
}
else if (r == -10)
{
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><EFBFBD><E8A8A1> <20><><EFBFBD><EFBFBD><E0A0AD><EFBFBD><EFBFBD><><E4A0A9> \"%s\".\n", name);
#else
printf("\nCheckers: Error saving the file \"%s\".\n", name);
#endif
printf(FILE_WRONG_TYPE_STR, name);
}
else
{
printf(ERROR_SAVING_FILE_STR, name);
}
#ifdef BUILD_RUS
printf("\n<EFBFBD><EFBFBD>誨: <20><><EFBFBD><EFBFBD> \"%s\" <20><><EFBFBD><EFBFBD><E0A0AD>.\n", name);
#else
printf("\nCheckers: File \"%s\" saved.\n", name);
#endif
return 0;
}
else
{
@@ -785,17 +813,18 @@ void TPlayArray::Del(int n)
play[nplay - 1].Clear();
nplay--;
}
strcpy(str, c ? "blue: " : "red: ");
if (!p) strcat(str, "input");
else strcat(str, "computer");
void SetPlayerString(char *str, int c, TChPlayer *p)
{
strcpy(str, c ? BLUE_STR : RED_STR);
if (!p) strcat(str, INPUT_STR);
else strcat(str, COMPUTER_STR);
}
class TMainDraw : public TSomeDraw
{
public:
TMainDraw() : undo_redo(0), ur_type(-1), cur_play(0),
def_savefile("save.che"), def_savekind(2) {InitButton();}
@@ -851,33 +880,50 @@ protected:
int def_savekind;
protected:
int ur_type;
button.Add(1, 80, 22, "new game");
button.Add(6, 60, 22, "list");
button.Add(7, 60, 22, "delete");
};
void TMainDraw::InitButton()
{
char newgame_literal[] = NEW_GAME_STR;
char list_literal[] = LIST_STR;
char delete_literal[] = DELETE_STR;
char clear_literal[] = CLEAR_STR;
char save_literal[] = SAVE_STR;
char rotateboard_literal[] = ROTATE_BOARD_STR;
char exit_literal[] = EXIT_STR;
char one_literal[] = "1";
char dash_literal[] = "-";
char plus_literal[] = "+";
char leftshift_literal[] = "<<";
char rightshift_literal[] = ">>";
char lessthan_literal[] = "<";
char greaterthan_literal[] = ">";
char xor_literal[] = "^";
play_list->a.Add(26, 20, 22, "1");
play_list->a.Add(21, 20, 22, "-");
button.Add(1, 80, 22, newgame_literal);
button.Add(6, 60, 22, list_literal);
button.Add(7, 60, 22, delete_literal);
play_list->a.Add(22, 20, 22, "+");
play_list = new TMultiButton(20);
play_list->a.Add(26, 20, 22, one_literal);
play_list->a.Add(21, 20, 22, dash_literal);
play_list->a.Add(23, 37, 22, play_num[0], -2);
button.Add(24, 50, 22, "clear");
play_list->a.Add(22, 20, 22, plus_literal);
play_list->a.Add(27, 37, 22, play_num[1]);
button.Add(25, 50, 22, "save");
play_list->SetDefW();
button.Add(play_list);
button.Add(24, 50, 22, clear_literal);
#ifndef __MENUET__
button.Add(4, 110, 22, "rotate board");
button.Add(25, 50, 22, save_literal);
#endif
undo_redo->a.Add(11, 27, 22, "<<");
undo_redo->a.Add(12, 20, 22, "<");
undo_redo->a.Add(15, 20, 22, "^");
undo_redo->a.Add(13, 20, 22, ">");
undo_redo->a.Add(14, 27, 22, ">>");
button.Add(2, 120, 22, player_str[0]);
button.Add(3, 120, 22, player_str[1]);
button.Add(4, 110, 22, rotateboard_literal);
undo_redo = new TMultiButton(10);
undo_redo->a.Add(11, 27, 22, leftshift_literal);
undo_redo->a.Add(12, 20, 22, lessthan_literal);
undo_redo->a.Add(15, 20, 22, xor_literal);
button.Add(5, 60, 22, "exit");
undo_redo->a.Add(13, 20, 22, greaterthan_literal);
undo_redo->a.Add(14, 27, 22, rightshift_literal);
undo_redo->SetDefW();
button.Add(undo_redo);
@@ -1325,7 +1371,8 @@ int main(int argc, char **argv)
data.main_draw.def_savekind = atoi(argv[i] + j);
while (argv[i][j] && argv[i][j] != '=') j++;
if (argv[i][j] != '=' || !argv[i][j+1]) continue;
else printf("Checkers: Invalid key %s\n", argv[i]);
}
data.main_draw.def_savefile = argv[i] + j + 1;
}
}
@@ -1334,13 +1381,7 @@ int main(int argc, char **argv)
else if (kx == 0 || kx == 1)
{
data.main_draw.play.MsgOpenFile(argv[i], -1);
TMainGraphDraw graph(
#ifdef BUILD_RUS
"<EFBFBD><EFBFBD>"
#else
"Checkers"
#endif
);
}
}
}
data.InitDef();
@@ -1364,13 +1405,7 @@ bool MenuetOnStart(TStartData &me_start, TThreadData)
mdata = new TMainData(-1);
graph = new TMainGraphDraw;
randomize();
me_start.WinData.Title =
#ifdef BUILD_RUS
"<EFBFBD><EFBFBD>"
#else
"Checkers"
#endif
;
mdata->InitDef();
static TTimerDraw timer_draw(&mdata->board, graph);
mdata->player.draw = TTimerDraw::draw; mdata->player.data = &timer_draw;
graph->data = mdata;

View File

@@ -0,0 +1,7 @@
del *.o
echo #define LANG_ENG 1 > lang.h
g++ -c checkers.cpp
g++ -L/usr/X11R6/lib -lX11 -o checkers checkers.o
pause

View File

@@ -0,0 +1,7 @@
del *.o
echo #define LANG_RUS 1 > lang.h
g++ -c checkers.cpp
g++ -L/usr/X11R6/lib -lX11 -o checkers checkers.o
pause

View File

@@ -50,7 +50,7 @@ public:
tvalue FindBMove(Z &z, int num, PMvv *pmv, int zn = -1,
tvalue a = -2 * win_val, tvalue b = 2 * win_val);
public:
void (*draw)(void*, int = 0);
void (*draw)(void*, int ); //draw() wants int = 0 as a default argument
void *data;
};
@@ -786,7 +786,7 @@ tvalue TBaseCompPlayer<tvalue>::FindBMove(Z &z, int num,
{
assert(b > a);
assert(num >= 0);
if (num >= 3 && draw) draw(data);
if (num >= 3 && draw) draw(data, 0);
int nlast = z.narr;
if (zn < 0) {z.AddPos(); z.array[zn = z.narr++] = *pmv;}
if (pmv) pmv->mv[0] = 0;