OpenCores
URL https://opencores.org/ocsvn/connect-6/connect-6/trunk

Subversion Repositories connect-6

[/] [connect-6/] [trunk/] [BUILD_SCC/] [synth_src/] [state.cpp] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 sumanta.ch
 
2
/*
3
 
4
connectk -- a program to play the connect-k family of games
5
Copyright (C) 2007 Michael Levin
6
 
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 
21
*/
22
 
23
//#include "config.h"
24
//#include <gtk/gtk.h>
25
//#include <glib/gprintf.h>
26
//#include <stdlib.h>
27
//#include <stdio.h>
28
//#include <string.h>
29
//#include <math.h>
30 7 sumanta.ch
//#include <iostream>
31
#include "shared.h"
32
//#include "q.hpp"
33 4 sumanta.ch
//#include "connectk.h"
34 7 sumanta.ch
#ifdef PICO_SYNTH
35
//#include "pico.h"
36
#endif
37
//#include "./q.hpp"
38
using namespace std;
39 4 sumanta.ch
/*
40
 *      Allocation chain
41
 */
42
 
43
#define IA 1103515245u
44
#define IC 12345u
45
#define IM 2147483648u
46
#define CHECK_RAND
47
//moved the following declaration to connect6_threat
48
//static unsigned int current_random = 0;
49
 
50
//from vpr uti.c code
51
/* Portable random number generator defined below.  Taken from ANSI C by  *
52
 * K & R.  Not a great generator, but fast, and good enough for my needs. */
53
 
54
 
55 7 sumanta.ch
//int ready=0;
56 4 sumanta.ch
void my_srandom(int seed,unsigned int *current_random)
57
{
58
    *current_random = (unsigned int)seed;
59
}
60
 
61
 
62
int my_irand(int imax,unsigned int current_random)
63
{
64
 
65
///* Creates a random integer between 0 and imax, inclusive.  i.e. [0..imax] */
66
//
67
//    int ival;
68
//
69
///* current_random = (current_random * IA + IC) % IM; */
70
//    current_random = current_random * IA + IC;  /* Use overflow to wrap */
71
//    ival = current_random & (IM - 1);   /* Modulus */
72
//      //float not synthesizable
73
//    //ival = (int)((float)ival * (float)(imax + 0.999) / (float)IM);
74
//    ival = (int)(ival * (imax + 1) / IM);
75
//
76
//#ifdef CHECK_RAND
77
//    if((ival < 0) || (ival > imax))
78
//        {
79
//            //printf("Bad value in my_irand, imax = %d  ival = %d\n", imax,
80
//            //       ival);
81
//            //exit(1);
82
//        }
83
//#endif
84
//
85
//    return (ival);
86
return(0);
87
}
88
 
89
 
90
//static void achain_init(AllocChain *ac)
91
//{
92
//        static unsigned int ids;
93
//
94
//        ac->free = FALSE;
95
//        ac->id = ids++;
96
//}
97
//
98
//AllocChain *achain_new(AllocChain **root, AllocFunc afunc)
99
//{
100
//        AllocChain *ac;
101
//
102
//        if (!*root) {
103
//                *root = afunc(NULL);
104
//                achain_init(*root);
105
//                (*root)->next = NULL;
106
//                return *root;
107
//        }
108
//        ac = *root;
109
//        for (;;) {
110
//                if (ac->free) {
111
//                        afunc(ac);
112
//                        achain_init(ac);
113
//                        return ac;
114
//                }
115
//                if (!ac->next)
116
//                        break;
117
//                ac = ac->next;
118
//        }
119
//        ac->next = afunc(NULL);
120
//        achain_init(ac->next);
121
//        ac->next->next = NULL;
122
//        return ac->next;
123
//}
124
//
125
//void achain_free(AllocChain *ac)
126
//{
127
//        if (!ac)
128
//                return;
129
//        ac->free = TRUE;
130
//}
131
//
132
//void achain_copy(const AllocChain *src, AllocChain *dest, gsize mem)
133
//{
134
//        if (!src || !dest || !mem) {
135
//                g_warning("NULL argument(s) to achain_copy");
136
//                return;
137
//        }
138
//        memcpy((char*)dest + sizeof (AllocChain),
139
//               (char*)src + sizeof (AllocChain), mem - sizeof (AllocChain));
140
//}
141
//
142
//static void achain_dealloc(AllocChain **root, gsize mem)
143
//{
144
//        AllocChain *ac = *root, *ac_next;
145
//
146
//        while (ac) {
147
//                ac_next = ac->next;
148
//                g_slice_free1(mem, ac);
149
//                ac = ac_next;
150
//        }
151
//        *root = NULL;
152
//}
153
 
154
 
155
//      Move Arrays
156
 
157
 
158
//AllocChain *aimoves_root = NULL;
159
gsize aimoves_mem = 0;
160
 
161
//AllocChain *aimoves_alloc(AllocChain *ac)
162
//{
163
//        //if (!ac)
164
//        //        ac = (AllocChain*)g_slice_alloc(aimoves_mem);
165
//        //memset((char*)ac + sizeof (AllocChain), 0, sizeof (AIMoves) -
166
//        //       sizeof (AllocChain));
167
//        //return ac;
168
//}
169
 
170
void aimoves_add(AIMoves *moves, const AIMove *move)
171
{
172
        int i;
173
 
174
        i = aimoves_find(moves, move->x, move->y);
175
        if (i < 0) {
176
                if (moves->len >= board_size * board_size)
177
                        //g_warning("Attempted to add a move to a full AIMoves");
178
                        //printf("Attempted to add a move to a full AIMoves");
179
                        return;
180
                else
181
                        moves->data[moves->len++] = *move;
182
        } else
183
                moves->data[i].weight += move->weight;
184
}
185 7 sumanta.ch
//FIFO(moves_fifo,AIMove);
186
//#pragma fifo_length moves_fifo 361
187 4 sumanta.ch
void aimoves_append(AIMoves *moves, const AIMove *move)
188
{
189
        int i;
190
 
191
        if (move->x >= board_size || move->y >= board_size)
192
                return;
193 7 sumanta.ch
        #pragma num_iterations(0,150,361)
194 4 sumanta.ch
        for (i = 0; i < moves->len; i++) {
195
                AIMove *aim = moves->data + i;
196
 
197
                if (aim->x == move->x && aim->y == move->y) {
198
                        aim->weight = move->weight;
199
                        return;
200
                }
201
        }
202
        if (moves->len >= board_size * board_size) {
203
                //g_warning("Attempted to append a move to a full AIMoves");
204
                //printf("Attempted to append a move to a full AIMoves");
205
                return;
206
        }
207
        moves->data[moves->len++] = *move;
208 7 sumanta.ch
        //if(!moves_fifo.full()) moves_fifo.push(*move);
209 4 sumanta.ch
}
210
 
211
int aimoves_compare(const void *a, const void *b)
212
{
213
        return ((AIMove*)b)->weight - ((AIMove*)a)->weight;
214
}
215
 
216 15 sumanta.ch
int aimoves_choose(AIMoves *moves, AIMove *move/*,index_array *index*/)
217 4 sumanta.ch
{
218
        //#pragma read_write_ports moves.data combined 3
219
        //#pragma internal_blockram moves
220
        //#pragma no_memory_analysis moves
221 7 sumanta.ch
 
222
        int i = 0;
223
        int top;
224
        AIMoves moves1;
225 4 sumanta.ch
        #pragma bitsize i 4
226 11 sumanta.ch
        if (!moves || !moves->len)
227
                return 0;
228
        aimoves_sort(moves);
229
        for (top = 0; top < moves->len &&
230
             moves->data[top].weight == moves->data[0].weight; top++);
231
        if (top)
232
                //i = my_irand(top,current_random);//g_random_int_range(0, top);
233
                i=0;
234
 
235
        *move = moves->data[i];
236
        return 1;
237 7 sumanta.ch
        /*---------------------------------------
238
                Rewritten for Hardware
239
        ---------------------------------------*/
240
        //for (top = 0; top < moves->len; top++){
241
        //      if(top==0) {
242
        //                       if (!moves)
243
        //                      return 0;
244
        //      }
245
        //      if(moves->data[index[top]].weight != moves->data[index[0]].weight){
246
        //              *move = moves->data[index[i]];
247
        //              return 1;
248
        //      }
249
        //      if(top==moves->len-1) {
250
        //              *move = moves->data[index[i]];
251
        //              return 1;
252
        //      }
253
        //}
254
        //                return 0;
255 12 sumanta.ch
        //if(!moves|| !moves->len) return 0;
256
        //else {*move=moves->data[i];return 1;}
257 7 sumanta.ch
 
258
 
259 4 sumanta.ch
}
260
//
261
//void aimoves_crop(AIMoves *moves, unsigned int n)
262
//{
263
//        if (moves->len < n)
264
//                return;
265
//        aimoves_shuffle(moves);
266
//        aimoves_sort(moves);
267
//        moves->len = n;
268
//}
269
//
270
//void aimoves_concat(AIMoves *m1, const AIMoves *m2)
271
//{
272
//        gsize max_len = board_size * board_size, len;
273
//
274
//        len = m2->len;
275
//        if (m1->len + len > max_len)
276
//                len = max_len - m1->len;
277
//        memcpy(m1->data + len, m2->data, len * sizeof (AIMove));
278
//        m1->len += len;
279
//}
280
//
281
//AIMoves *aimoves_dup(const AIMoves *moves)
282
//{
283
//        AIMoves *dup;
284
//
285
//        if (!moves)
286
//                return NULL;
287
//        dup = aimoves_new();
288
//        dup->len = moves->len;
289
//        memcpy(dup->data, moves->data, moves->len * sizeof (AIMove));
290
//        return dup;
291
//}
292
//
293
int aimoves_find(const AIMoves *moves, BCOORD x, BCOORD y)
294
{
295
        int i;
296
 
297
        if (moves)
298
                for (i = 0; i < moves->len; i++) {
299
                        const AIMove *aim = moves->data + i;
300
 
301
                        if (aim->x == x && aim->y == y)
302
                                return i;
303
                }
304
        return -1;
305
}
306
//
307
//void aimoves_range(AIMoves *moves, AIWEIGHT *min, AIWEIGHT *max)
308
//{
309
//        int i;
310
//
311
//        *min = AIW_MAX;
312
//        *max = AIW_MIN;
313
//        for (i = 0; i < moves->len; i++) {
314
//                if (moves->data[i].weight > *max)
315
//                        *max = moves->data[i].weight;
316
//                if (moves->data[i].weight < *min)
317
//                        *min = moves->data[i].weight;
318
//        }
319
//}
320
//
321
//void aimoves_merge(AIMoves *m1, const AIMoves *m2)
322
//{
323
//        int len = m1->len, i, j;
324
//
325
//        for (i = 0; i < m2->len; i++)
326
//                for (j = 0;; j++) {
327
//                        if (j >= len) {
328
//                                aimoves_append(m1, m2->data + i);
329
//                                break;
330
//                        }
331
//                        if (m1->data[j].x == m2->data[i].x &&
332
//                            m1->data[j].y == m2->data[i].y) {
333
//                                if (m2->data[i].weight > m1->data[j].weight)
334
//                                        m1->data[j].weight = m2->data[i].weight;
335
//                                break;
336
//                        }
337
//                }
338
//}
339
//
340
//char *aimove_to_string(const AIMove *aim)
341
//{
342
//        static char buffer[32];
343
//
344
//        g_snprintf(buffer, sizeof (buffer), "%s (%s)",
345
//                   bcoords_to_string(aim->x, aim->y),
346
//                   aiw_to_string(aim->weight));
347
//        return buffer;
348
//}
349
//
350
//void aimoves_print(const AIMoves *moves)
351
//{
352
//        int i;
353
//
354
//        if (!moves || !moves->len) {
355
//                g_print("(empty)");
356
//                return;
357
//        }
358
//        for (i = 0; i < moves->len; i++) {
359
//                const AIMove *aim = moves->data + i;
360
//
361
//                if (i)
362
//                        g_print(", ");
363
//                g_print("%s", aimove_to_string(aim));
364
//        }
365
//}
366
//
367
//void aimoves_remove_index_fast(AIMoves *moves, int i)
368
//{
369
//        if (moves->len > i)
370
//                moves->data[i] = moves->data[moves->len - 1];
371
//        moves->len--;
372
//}
373
//
374
//void aimoves_remove(AIMoves *moves, BCOORD x, BCOORD y)
375
//{
376
//        int i;
377
//
378
//        for (i = 0; i < moves->len; i++) {
379
//                AIMove *aim = moves->data + i;
380
//
381
//                if (aim->x == x && aim->y == y) {
382
//                        aimoves_remove_index_fast(moves, i);
383
//                        return;
384
//                }
385
//        }
386
//}
387
//
388
void aimoves_shuffle(AIMoves *moves,unsigned int current_random)
389
{
390
//        int i;
391
//
392
//        if (opt_det_ai)
393
//                return;
394
//
395
//        /* Fisher-Yates shuffle */
396
//        for (i = 0; i < moves->len; i++) {
397
//                int j;
398
//
399
//                j = my_irand(moves->len,current_random);//g_random_int_range(i, moves->len);
400
//                if (i != j) {
401
//                        AIMove tmp;
402
//
403
//                        tmp = moves->data[i];
404
//                        moves->data[i] = moves->data[j];
405
//                        moves->data[j] = tmp;
406
//                }
407
//        }
408
return;
409
}
410
 
411
 
412
//taken from http://cprogramminglanguage.net/c-bubble-sort-source-code.aspx
413
void swap(AIMove  *x,AIMove *y)
414
{
415
   AIMove temp;
416
   temp = *x;
417
   *x = *y;
418
   *y = temp;
419
}
420
void bublesort(AIMove *list, int n)
421
{
422
   int i,j;
423
   for(i=0;i<(n-1);i++)
424
      for(j=0;j<(n-(i+1));j++)
425
             if(list[j].weight < list[j+1].weight)
426
                    swap(&list[j],&list[j+1]);
427 7 sumanta.ch
                                //cout<<"BUBBLESORT"<<":"<<n<<endl;
428
                                //for(i=0;i<n;i++) cout<<list[i].weight<<",";
429
                                //cout<<endl;
430 4 sumanta.ch
}
431
//taken from http://cprogramminglanguage.net/c-bubble-sort-source-code.aspx
432
void aimoves_sort(AIMoves *moves)
433
{
434
        //qsort(moves->data, moves->len, sizeof (AIMove), aimoves_compare);
435
        bublesort(moves->data,moves->len);
436 7 sumanta.ch
        //streamsort(moves->data,moves->len);
437 4 sumanta.ch
 
438
}
439
 
440
//void aimoves_subtract(AIMoves *m1, const AIMoves *m2)
441
//{
442
//        int i, j;
443
//
444
//        for (i = 0; i < m1->len; i++)
445
//                for (j = 0; j < m2->len; j++)
446
//                        if (m1->data[i].x == m2->data[j].x &&
447
//                            m1->data[i].y == m2->data[j].y) {
448
//                                aimoves_remove_index_fast(m1, i--);
449
//                                break;
450
//                        }
451
//}
452
//
453
//const char *aiw_to_string(AIWEIGHT w)
454
//{
455
//        static char buffer[32];
456
//
457
//        switch (w) {
458
//        case AIW_WIN:
459
//                return "WIN";
460
//        case AIW_LOSE:
461
//                return "LOSS";
462
//        case AIW_NONE:
463
//                return "NONE";
464
//        default:
465
//                break;
466
//        }
467
//        if (w > 0)
468
//                g_snprintf(buffer, sizeof (buffer), "%010d (10^%.2f)", w,
469
//                           log10((double)w));
470
//        else if (w < 0)
471
//                g_snprintf(buffer, sizeof (buffer), "%010d (-10^%.2f)", w,
472
//                           log10((double)-w));
473
//        return buffer;
474
//}
475
 
476
/*
477
 *      Boards
478
 */
479
 
480
//Board board;
481
//AllocChain *board_root = NULL;
482
//int board_size=19, board_stride=21, move_no, move_last,
483
//    connect_k = 6, place_p = 2, start_q = 1;
484
//int opt_det_ai=1;
485
//gsize board_mem = 0;
486
 
487
//Player players[PIECES] = {
488
//        { PLAYER_HUMAN, SEARCH_NONE, 0 },
489
//        { PLAYER_HUMAN, SEARCH_NONE, 0 },
490
//        { PLAYER_HUMAN, SEARCH_NONE, 0 },
491
//};
492
//
493
//static GPtrArray *history = NULL;
494
 
495
static void board_init(Board *b)
496
{
497
//        memset((char*)b + sizeof (AllocChain), 0, sizeof (Board) -
498
//               sizeof (AllocChain));
499
int i,j;
500
for(i=0;i<board_stride;i++)
501
        b->data[i][0]=PIECE_ERROR;
502
for(i=0;i<board_stride;i++)
503
        b->data[i][board_stride-1]=PIECE_ERROR;
504
for(j=0;j<board_stride;j++)
505
        b->data[0][j]=PIECE_ERROR;
506
for(j=0;j<board_stride;j++)
507
        b->data[board_stride-1][j]=PIECE_ERROR;
508
for(i=1;i<board_stride-1;i++)
509
        for(j=1;j<board_stride-1;j++)
510
                b->data[i][j]=PIECE_NONE;
511
 
512
        //b->ac=(const AllocChain )0;   
513
        b->moves_left=0;
514
        b->parent =0;
515
        b->won    =0;
516
        b->win_x1 =0;
517
        b->win_y1 =0;
518
        b->win_x2 =0;
519
        b->win_y2 =0;
520
        b->turn   =0;
521
        b->move_x =0;
522
        b->move_y =0;
523
}
524
 
525
//AllocChain *board_alloc(AllocChain *ac)
526
//{
527
//        //Board *b = (Board*)ac;
528
//        //int i;
529
//
530
//        ///* Clear the old board */
531
//        //if (b) {
532
//        //        for (i = 1; i <= board_size; i++)
533
//        //                memset(b->data + board_stride * i + 1, 0,
534
//        //                       board_size * sizeof (PIECE));
535
//        //        board_init(b);
536
//        //        return (AllocChain*)b;
537
//        //}
538
//
539
//        ///* New boards are allocated with a 1-tile wide boundary of PIECE_ERROR
540
//        //   around the edges */
541
//        //b = (Board*)g_slice_alloc0(board_mem);
542
//        //memset(b->data, PIECE_ERROR, sizeof (PIECE) * board_stride);
543
//        //for (i = 1; i <= board_size; i++) {
544
//        //        b->data[i * board_stride] = PIECE_ERROR;
545
//        //        memset(b->data + board_stride * i + 1, 0,
546
//        //               board_size * sizeof (PIECE));
547
//        //        b->data[(i + 1) * board_stride - 1] = PIECE_ERROR;
548
//        //}
549
//        //memset(b->data + board_stride * (board_stride - 1), PIECE_ERROR,
550
//        //       sizeof (PIECE) * board_stride);
551
//        //board_init(&b);
552
//        //return (AllocChain*)b;
553
//}
554
 
555
void board_clean(Board *b)
556
{
557
        int y, x;
558
 
559
        for (y = 0; y < board_size; y++)
560
                for (x = 0; x < board_size; x++)
561
                        if (piece_at(b, x, y) >= PIECES)
562
                                place_piece_type(b, x, y, PIECE_NONE);
563
}
564
 
565
//void set_board_size(unsigned int size)
566
//{
567
//        //if (board_size == size)
568
//        //        return;
569
//        ////draw_marks(NULL, FALSE);
570
//        //achain_dealloc(&board_root, board_mem);
571
//        achain_dealloc(&aimoves_root, aimoves_mem);
572
//        //board_size = size;
573
//        //board_stride = size + 2;
574
//        //board_mem = sizeof (Board) + board_stride * board_stride *
575
//        //            sizeof (PIECE);
576
//        aimoves_mem = sizeof (AIMoves) + size * size * sizeof (AIMove);
577
//}
578
 
579
//Board *board_at(unsigned int move)
580
//{
581
//        if (move >= history->len)
582
//                return NULL;
583
//        return (Board*)g_ptr_array_index(history, move);
584
//}
585
 
586
int count_pieces(const Board *b, BCOORD x, BCOORD y, PIECE type, int dx, int dy,
587
                 PIECE *out)
588
{
589
        int i;
590
        PIECE p = PIECE_NONE;
591
 
592
        if (!dx && !dy)
593
                return piece_at(b, x, y) == type ? 1 : 0;
594
        for (i = 0; x >= 0 && x < board_size && y >= 0 && y < board_size; i++) {
595
                p = piece_at(b, x, y);
596
                if (p != type)
597
                        break;
598
                x += dx;
599
                y += dy;
600
        }
601 12 sumanta.ch
        /* this two lines create problem in synthesis  preprocess ?? */
602 4 sumanta.ch
        if (out)
603
                *out = p;
604
        return i;
605
}
606
 
607
gboolean check_win_full(const Board *b, BCOORD x, BCOORD y,
608
                        BCOORD *x1, BCOORD *y1, BCOORD *x2, BCOORD *y2)
609
{
610
        int i, c1, c2, xs[] = {1, 1, 0, -1}, ys[] = {0, 1, 1, 1};
611
        PIECE type;
612 12 sumanta.ch
        PIECE p;
613 4 sumanta.ch
 
614
        type = piece_at(b, x, y);
615
        if (type != PIECE_BLACK && type != PIECE_WHITE)
616
                return FALSE;
617
        for (i = 0; i < 4; i++) {
618 12 sumanta.ch
                c1 = count_pieces(b, x, y, type, xs[i], ys[i], &p);
619
                c2 = count_pieces(b, x, y, type, -xs[i], -ys[i], &p);
620 4 sumanta.ch
                if (c1 + c2 > connect_k) {
621 12 sumanta.ch
                        //if (x1)
622
                        //        *x1 = x + xs[i] * (c1 - 1);
623
                        //if (y1)
624
                        //        *y1 = y + ys[i] * (c1 - 1);
625
                        //if (x2)
626
                        //        *x2 = x - xs[i] * (c2 - 1);
627
                        //if (y2)
628
                        //        *y2 = y - ys[i] * (c2 - 1);
629 4 sumanta.ch
                        return TRUE;
630
                }
631
        }
632
        return FALSE;
633
}
634
 
635
///* Convert a boord coordinate to alpha representation */
636
//const char *bcoord_to_alpha(BCOORD x)
637
//{
638
//        static char buf[2][32];
639
//        static int which;
640
//        int i, divisor = 26;
641
//
642
//        which = !which;
643
//        for (i = 0; i < sizeof (buf[which]) - 1; i++) {
644
//                div_t result;
645
//
646
//                result = div(x, divisor);
647
//                buf[which][i] = 'a' + result.rem * 26 / divisor;
648
//                if (i)
649
//                        buf[which][i]--;
650
//                x -= result.rem;
651
//                if (!x)
652
//                        break;
653
//                divisor *= 26;
654
//        }
655
//        buf[which][i + 1] = 0;
656
//        return g_strreverse(buf[which]);
657
//}
658
 
659
//// Get a string representation of board x/y coordinates (d7, h16, etc)
660
//const char *bcoords_to_string(BCOORD x, BCOORD y)
661
//{
662
//        static char buf[2][32];
663
//        static int which;
664
//
665
//        which = !which;
666
//        g_snprintf(buf[which], sizeof (buf[which]), "%s%d",
667
//                   bcoord_to_alpha(x), board_size - y);
668
//        return buf[which];
669
//}
670
//
671
/* Convert a string representation to coordinates */
672
void string_to_bcoords(const char *str, BCOORD *x, BCOORD *y)
673
{
674
        *x = 0;
675
        *y = 0;
676
        while (*str && *str >= 'a' && *str <= 'z') {
677
                *x *= 26;
678
                *x += *str - 'a';
679
                str++;
680
        }
681
        while (*str && *str >= '0' && *str <= '9') {
682
                *y *= 10;
683
                *y += *str - '0';
684
                str++;
685
        }
686
        if (*y)
687
                *y = board_size - *y;
688
}
689
 
690
const char *piece_to_string(PIECE piece)
691
{
692
        switch (piece) {
693
        case PIECE_WHITE:
694
                return "White";
695
        case PIECE_BLACK:
696
                return "Black";
697
        case PIECE_NONE:
698
                return "None";
699
        case PIECE_ERROR:
700
                return "Error";
701
        default:
702
                return "Mark";
703
        }
704
}
705
 
706
char piece_to_char(PIECE piece)
707
{
708
        switch (piece) {
709
        case PIECE_WHITE:
710
                return 'W';
711
        case PIECE_BLACK:
712
                return 'B';
713
        case PIECE_NONE:
714
                return '_';
715
        case PIECE_ERROR:
716
                return 'E';
717
        default:
718
                return 'M';
719
        }
720
}
721
 
722
//char *search_to_string(SEARCH s)
723
//{
724
//        switch (s) {
725
//        case SEARCH_NONE:
726
//                return "No search";
727
//        case SEARCH_DFS:
728
//                return "Depth first search";
729
//        case SEARCHES:
730
//                break;
731
//        }
732
//        return "Unknown";
733
//}
734
 
735
//void go_to_move(unsigned int move)
736
//{
737
//        Board board2;
738
//
739
//        if (!history)
740
//                history = g_ptr_array_sized_new(32);
741
//        if (move > history->len)
742
//                move = history->len;
743
//        if (move == history->len) {
744
//                //board2 = board_new();
745
//                if (&board)
746
//                        board_copy(&board, &board2);
747
//                g_ptr_array_add(history, &board2);
748
//                board2.parent = &board;
749
//        } else
750
//                //board2 = (Board*)g_ptr_array_index(history, move);
751
//        //&board = &board2;
752
//        move_no = move;
753
//        if (move_no > move_last)
754
//                move_last = move_no;
755
//}
756
 
757
//void clear_history(unsigned int from)
758
//{
759
//        int i;
760
//
761
//        if (!history)
762
//                return;
763
//        if (from >= history->len) {
764
//                g_warning("Attempted to clear future history");
765
//                return;
766
//        }
767
//        for (i = from; i < history->len; i++)
768
//                board_free(g_ptr_array_index(history, i));
769
//        g_ptr_array_remove_range(history, from, history->len - from);
770
//        move_last = from;
771
//}
772
/* Clear the board and history for a new game */
773
void new_game(Board *board,unsigned int size)
774
{
775
        //tree_view_clear(1);
776
        //clear_history(0);
777
        //set_board_size(size);
778
        //board = NULL;
779
        //go_to_move(0);
780
        //move_last=0;
781
        //move_no=0;
782
        board_init(board);
783
        board->moves_left = start_q;
784
        board->turn = PIECE_BLACK;
785
        //draw_board();
786
        //stop_ai();
787
        //setup_move();
788
}
789
void board_copy(const Board *from, Board *to){
790
int i,j;
791
for(i=0;i<board_stride;i++)
792
        for(j=0;j<board_stride;j++)
793
                to->data[i][j]=from->data[i][j];
794
 
795
        to->ac= from->ac;
796
        to->moves_left= from->moves_left;
797
        to->parent =    from->parent;
798
        to->won    =    from->won;
799
        to->win_x1 =    from->win_x1;
800
        to->win_y1 =    from->win_y1;
801
        to->win_x2 =    from->win_x2;
802
        to->win_y2 =    from->win_y2;
803
        to->turn   =    from->turn;
804
        to->move_x =    from->move_x;
805
        to->move_y =    from->move_y;
806
 
807
 
808
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.