-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchss.h
559 lines (430 loc) · 8.49 KB
/
chss.h
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/*
Copyright (C) 2021 BrerDawg
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//chss.h v1.01
#ifndef chss_h
#define chss_h
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Choice.H>
#include <FL/Fl_File_Chooser.H>
#include <FL/Enumerations.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Editor.H>
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_File_Input.H>
#include <FL/Fl_Input_Choice.H>
#include <FL/Fl_Int_Input.H>
#include "globals.h"
#include "GCProfile.h"
#include "seg7.h"
#include "GCLed.h"
using namespace std;
#define cn_max_mve_cnt 100
#define max_pieces_per_side 16
struct colref_chss
{
int r, g, b;
};
static colref_chss col_ch_bkgd = { 64, 64, 64 };
static colref_chss col_ch_yel = { 255, 255, 0 };
static colref_chss col_ch_red = { 255, 0, 0 };
static colref_chss col_ch_mag = { 255, 0, 255 };
static colref_chss col_ch_wht = { 255, 255, 255 };
static int vec_none[ 1 ][ 2 ]=
{
0,0
};
static int vec_pawn[25][2]=
{
12,0, //number of lines
-10,-15,
10,-15,
-10,-15,
-3,-7,
10,-15,
3,-7,
-3,-7,
-3,0,
3,-7,
3,0,
-3,0,
-5,3,
3,0,
5,3,
-5,3,
-5,7,
5,3,
5,7,
-5,7,
-3,10,
5,7,
3,10,
-3,10,
3,10,
};
static int vec_bishop[25][2]=
{
11,0, //number of lines
-10,-15,
10,-15,
-10,-15,
-3,-7,
10,-15,
3,-7,
-3,-7,
-3,5,
3,-7,
3,5,
-3,5,
-5,8,
3,5,
5,9,
-5,8,
-2,14,
-2,14,
0,10,
0,10,
3,18,
3,18,
5,8
};
static int vec_rook[37][2]=
{
18,0, //number of lines
-10,-15,
10,-15,
-10,-15,
-5,-10,
10,-15,
5,-10,
-5,-10,
-5,5,
5,-10,
5,5,
-5,5,
-8,10,
5,5,
8,10,
-8,10,
-8,15,
8,10,
8,15,
-8,15,
-5,15,
8,15,
5,15,
-5,15,
-5,10,
5,15,
5,10,
-5,10,
-2,10,
5,10,
2,10,
-2,10,
-2,15,
2,10,
2,15,
-2,15,
2,15,
};
static int vec_knight[37][2]=
{
14,0, //number of lines
-10,-15,
10,-15,
-10,-15,
-3,-5,
-3,-5,
-7,0,
-7,0,
-7,10,
-7,10,
-5,14,
-5,14,
5,19,
5,19,
5,15,
5,15,
10,10,
10,10,
15,0,
15,0,
15,-5,
15,-5,
10,-5,
10,-5,
5,0,
5,0,
5,-10,
5,-10,
10,-15,
};
static int vec_queen[37][2]=
{
15,0, //number of lines
-10,-15,
10,-15,
-10,-15,
-5,-10,
10,-15,
5,-10,
-5,-10,
-5,10,
5,-10,
5,10,
-5,10,
-9,15,
5,10,
9,15,
-9,15,
-9,20,
9,15,
9,20,
-9,20,
-5,15,
9,20,
5,15,
-5,15,
-3,20,
5,15,
3,20,
-3,20,
0,15,
3,20,
-1,15,
};
static int vec_king[37][2]=
{
15,0, //number of lines
-10,-15,
10,-15,
-10,-15,
-5,-10,
10,-15,
5,-10,
-5,-10,
-5,7,
5,-10,
5,7,
-5,7,
-10,7,
5,7,
10,7,
-10,7,
-5,7,
-10,7,
-10,15,
10,7,
10,15,
-10,15,
-5,15,
10,15,
5,15,
-5,15,
-5,20,
5,15,
5,20,
-5,20,
5,20,
};
enum en_piece_type
{
pt_none,
pt_pawn,
pt_bishop,
pt_rook,
pt_knight,
pt_queen,
pt_king
};
struct st_piece_val
{
double val;
};
//would only be 16 pieces in length for lowest dimension
struct st_piece
{
int type;
double val;
int x, y;
bool moved; //has piece been moved from its starting pos, usefull for detecting if pawn allowed to move by 2
bool sel;
};
struct brd_tag
{
int pce_typ;
bool plyr;
} static brd[ 64 ];
//-----------------------------------------------------------------------------
struct button_tag
{
string sname;
char sztooltip[255];
int keycode;
int x1, y1, x2, y2;
bool text_button; //set if button is a non image based, it wont have its dimensions scaled
int id0, id1; //user defined ids, eg: for button matrix identification
};
class jpg_cpanel : public Fl_Widget
{
private:
int butt_pressed;
int mousewheel;
bool ctrl_key, shift_key;
void (*left_click_p_cb)( void *obj_in, void *args_in );
void *cb_obj;
void *left_click_cb_args;
bool entered;
int mousex, mousey;
int lb_x, lb_y;
int rb_x, rb_y;
public:
Fl_JPEG_Image *jpg_panel;
bool left_button, right_button;
vector<button_tag>vbutt;
int hov_idx;
int id0, id1;
public:
jpg_cpanel( int xx, int yy, int wid, int hei, const char *label );
bool init( string ss );
bool set_image( string ss );
void add_image_bounding_button( button_tag o );
void set_left_click_cb( void (*p_cb)( void*, void* ), void *args );
private:
void draw();
int handle( int e );
int do_mouse_move( int xx, int yy );
int do_butt_left();
int do_butt_right();
//void process_button( string ss );
};
//-----------------------------------------------------------------------------
class chess_wnd : public Fl_Double_Window
{
private: //private var
Fl_Menu_Button *flm_menu_popup_chess;
int dir_plyr0;
int dir_plyr1;
bool bottom_plyr; //which player is at bottom
bool col_plyr0; //player colour
bool col_plyr1; //player colour
bool left_button;
int instance;
Fl_Color col_bkgd;
int menu_hei;
int checker_x;
int checker_y;
int checker_off_x;
int checker_off_y;
int piece_off_y;
float scale;
bool comp_comp;
bool comp_mve;
int tick_cnt;
bool flash;
//st_piece plyr_mve0[ cn_max_mve_cnt ][ max_pieces_per_side ]; //holds player pieces
//st_piece plyr_mve1[ cn_max_mve_cnt ][ max_pieces_per_side ]; //holds player pieces
st_piece draw_plyr0[ max_pieces_per_side ]; //hold player pieces used for drawing brd
st_piece draw_plyr1[ max_pieces_per_side ];
//int sel_crdx, sel_crdy;
public:
Fl_Menu_Bar *menu;
Fl_Int_Input *fi_usec;
int brd_wid, brd_hei;
vector<st_piece> vwht, vblk;
int piece_cnt0;
int piece_cnt1;
st_piece plyr0[ max_pieces_per_side ]; //holds player pieces
st_piece plyr1[ max_pieces_per_side ]; //holds player pieces
seg7_wdg *wdg_seg0;
seg7_wdg *wdg_seg1;
seg7_wdg *wdg_seg2;
seg7_wdg *wdg_seg3;
bool left_pressed;
GCLed* coord_ledx[8];
GCLed* coord_ledy[8];
int mousex, mousey;
int mouse_coord_x;
int mouse_coord_y;
bool show_piece_move_lines; //draw 2 lines to show where the piece needs to be placed by user, uses the lit leds as coords
int usec;
Fl_Box *bx_status;
bool paused;
private:
void setcolref( colref_chss col );
void draw();
void draw_board();
void draw_grid();
void draw_highlight_checker( int xx, int yy, int r, int g, int b );
void draw_highlight_checkers();
void draw_sqr_coords( );
void draw_mouse_coords();
void draw_piece( bool plyr, int type, int x, int y );
void draw_pieces();
void draw_pieces2();
int handle( int e );
void init();
int brd_idx( int coordx, int coordy );
//bool set_piece( ulli bb, int coordx, int coordy );
bool move_piece( int coordx1, int coordy1, int coordx2, int coordy2 );
//bool mve_gen( int cur_x, int cur_y, int new_x, int new_y );
//bool chk_valid_pieces( int &x, int &y );
//flts player_valuation( bool plyr );
//bool get_piece_via_idx( bool plyr, int idx, int &type, int &x, int &y, flts &val );
bool get_draw_piece_via_idx( bool col, int idx, int &type, int &x, int &y, double &val, bool &sel );
//bool move_gen( bool plyr, int idx );
//int checker_status( int x, int y );
int find_piece_at_xy( int x, int y, bool &is_white );
public: //public var
chess_wnd( int xx, int yy, int wid, int hei, const char *label );
~chess_wnd();
//void set_instance_id( int id );
void new_game();
bool find_coord( int x, int y, int &coordx, int &coordy );
//bool place_piece( bool plyr, int type, int x, int y, double val, bool sel, int idx );
bool place_piece( vector<st_piece> &oo, int type, int x, int y, double val, bool sel );
bool user_move_via_text( string s1 );
//void game_to_str( string &ss );
//void str_to_game( string ss );
//bool open_game( string fname );
//void test1();
//void test2();
void set_led_x( int crdx, bool on );
void set_led_y( int crdy, bool on );
void tick();
bool select_piece( int coordx1, int coordy1, bool sel );
bool toggle_select_piece( int crdx, int crdy );
bool deselect_all();
int find_selected( int &crdx, int &crdy, bool &is_plyr0 );
bool delete_piece( int crdx, int crdy, int &idx );
};
#endif