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

Subversion Repositories connect-6

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 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
//#include <iostream>
31
#include "shared.h"
32
//#include "q.hpp"
33
//#include "connectk.h"
34
#ifdef PICO_SYNTH
35
//#include "pico.h"
36
#endif
37
//#include "./q.hpp"
38
using namespace std;
39
/*
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
//int ready=0;
56
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
//FIFO(moves_fifo,AIMove);
186
//#pragma fifo_length moves_fifo 361
187
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
        #pragma num_iterations(0,150,361)
194
        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
        //if(!moves_fifo.full()) moves_fifo.push(*move);
209
}
210
 
211
int aimoves_compare(const void *a, const void *b)
212
{
213
        return ((AIMove*)b)->weight - ((AIMove*)a)->weight;
214
}
215
 
216
int aimoves_choose(AIMoves *moves, AIMove *move/*,index_array *index*/)
217
{
218
        //#pragma read_write_ports moves.data combined 3
219
        //#pragma internal_blockram moves
220
        //#pragma no_memory_analysis moves
221
 
222
        int i = 0;
223
        int top;
224
        AIMoves moves1;
225
        #pragma bitsize i 4
226
        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
        /*---------------------------------------
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
        //if(!moves|| !moves->len) return 0;
256
        //else {*move=moves->data[i];return 1;}
257
 
258
 
259
}
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 swap_bis(AIMove *list,int index1,int index2){
421
        AIMove temp;
422
        temp=list[index1];
423
        list[index1]=list[index2];
424
        list[index2]=temp;
425
 
426
}
427
void bublesort(AIMove *list, int n)
428
{
429
   int i,j;
430
   for(i=0;i<(n-1);i++)
431
      for(j=0;j<(n-(i+1));j++)
432
             if(list[j].weight < list[j+1].weight)
433
                    //swap(&list[j],&list[j+1]);
434
                    swap_bis(list,j,j+1);
435
                                //cout<<"BUBBLESORT"<<":"<<n<<endl;
436
                                //for(i=0;i<n;i++) cout<<list[i].weight<<",";
437
                                //cout<<endl;
438
}
439
//taken from http://cprogramminglanguage.net/c-bubble-sort-source-code.aspx
440
void aimoves_sort(AIMoves *moves)
441
{
442
        //qsort(moves->data, moves->len, sizeof (AIMove), aimoves_compare);
443
        bublesort(moves->data,moves->len);
444
        //streamsort(moves->data,moves->len);
445
 
446
}
447
void aimoves_sort_bis(AIMoves moves[2][16],int depth,int branch)
448
{
449
        //qsort(moves->data, moves->len, sizeof (AIMove), aimoves_compare);
450
        //bublesort(moves[depth][branch].data,moves[depth][branch].len);
451
   int n=moves[depth][branch].len;
452
   int i,j;
453
   for(i=0;i<(n-1);i++)
454
      for(j=0;j<(n-(i+1));j++)
455
             if(moves[depth][branch].data[j].weight < moves[depth][branch].data[j+1].weight){
456
                //swap
457
                AIMove temp;
458
                temp=moves[depth][branch].data[j];
459
                moves[depth][branch].data[j]=moves[depth][branch].data[j+1];
460
                moves[depth][branch].data[j+1]=temp;
461
 
462
                }
463
        //streamsort(moves->data,moves->len);
464
 
465
}
466
 
467
//void aimoves_subtract(AIMoves *m1, const AIMoves *m2)
468
//{
469
//        int i, j;
470
//
471
//        for (i = 0; i < m1->len; i++)
472
//                for (j = 0; j < m2->len; j++)
473
//                        if (m1->data[i].x == m2->data[j].x &&
474
//                            m1->data[i].y == m2->data[j].y) {
475
//                                aimoves_remove_index_fast(m1, i--);
476
//                                break;
477
//                        }
478
//}
479
//
480
//const char *aiw_to_string(AIWEIGHT w)
481
//{
482
//        static char buffer[32];
483
//
484
//        switch (w) {
485
//        case AIW_WIN:
486
//                return "WIN";
487
//        case AIW_LOSE:
488
//                return "LOSS";
489
//        case AIW_NONE:
490
//                return "NONE";
491
//        default:
492
//                break;
493
//        }
494
//        if (w > 0)
495
//                g_snprintf(buffer, sizeof (buffer), "%010d (10^%.2f)", w,
496
//                           log10((double)w));
497
//        else if (w < 0)
498
//                g_snprintf(buffer, sizeof (buffer), "%010d (-10^%.2f)", w,
499
//                           log10((double)-w));
500
//        return buffer;
501
//}
502
 
503
/*
504
 *      Boards
505
 */
506
 
507
//Board board;
508
//AllocChain *board_root = NULL;
509
//int board_size=19, board_stride=21, move_no, move_last,
510
//    connect_k = 6, place_p = 2, start_q = 1;
511
//int opt_det_ai=1;
512
//gsize board_mem = 0;
513
 
514
//Player players[PIECES] = {
515
//        { PLAYER_HUMAN, SEARCH_NONE, 0 },
516
//        { PLAYER_HUMAN, SEARCH_NONE, 0 },
517
//        { PLAYER_HUMAN, SEARCH_NONE, 0 },
518
//};
519
//
520
//static GPtrArray *history = NULL;
521
 
522
static void board_init(Board *b)
523
{
524
//        memset((char*)b + sizeof (AllocChain), 0, sizeof (Board) -
525
//               sizeof (AllocChain));
526
int i,j;
527
for(i=0;i<board_stride;i++)
528
        b->data[i][0]=PIECE_ERROR;
529
for(i=0;i<board_stride;i++)
530
        b->data[i][board_stride-1]=PIECE_ERROR;
531
for(j=0;j<board_stride;j++)
532
        b->data[0][j]=PIECE_ERROR;
533
for(j=0;j<board_stride;j++)
534
        b->data[board_stride-1][j]=PIECE_ERROR;
535
for(i=1;i<board_stride-1;i++)
536
        for(j=1;j<board_stride-1;j++)
537
                b->data[i][j]=PIECE_NONE;
538
 
539
        //b->ac=(const AllocChain )0;   
540
        b->moves_left=0;
541
        b->parent =0;
542
        b->won    =0;
543
        b->win_x1 =0;
544
        b->win_y1 =0;
545
        b->win_x2 =0;
546
        b->win_y2 =0;
547
        b->turn   =0;
548
        b->move_x =0;
549
        b->move_y =0;
550
}
551
 
552
//AllocChain *board_alloc(AllocChain *ac)
553
//{
554
//        //Board *b = (Board*)ac;
555
//        //int i;
556
//
557
//        ///* Clear the old board */
558
//        //if (b) {
559
//        //        for (i = 1; i <= board_size; i++)
560
//        //                memset(b->data + board_stride * i + 1, 0,
561
//        //                       board_size * sizeof (PIECE));
562
//        //        board_init(b);
563
//        //        return (AllocChain*)b;
564
//        //}
565
//
566
//        ///* New boards are allocated with a 1-tile wide boundary of PIECE_ERROR
567
//        //   around the edges */
568
//        //b = (Board*)g_slice_alloc0(board_mem);
569
//        //memset(b->data, PIECE_ERROR, sizeof (PIECE) * board_stride);
570
//        //for (i = 1; i <= board_size; i++) {
571
//        //        b->data[i * board_stride] = PIECE_ERROR;
572
//        //        memset(b->data + board_stride * i + 1, 0,
573
//        //               board_size * sizeof (PIECE));
574
//        //        b->data[(i + 1) * board_stride - 1] = PIECE_ERROR;
575
//        //}
576
//        //memset(b->data + board_stride * (board_stride - 1), PIECE_ERROR,
577
//        //       sizeof (PIECE) * board_stride);
578
//        //board_init(&b);
579
//        //return (AllocChain*)b;
580
//}
581
 
582
void board_clean(Board *b)
583
{
584
        int y, x;
585
 
586
        for (y = 0; y < board_size; y++)
587
                for (x = 0; x < board_size; x++)
588
                        if (piece_at(b, x, y) >= PIECES)
589
                                place_piece_type(b, x, y, PIECE_NONE);
590
}
591
 
592
//void set_board_size(unsigned int size)
593
//{
594
//        //if (board_size == size)
595
//        //        return;
596
//        ////draw_marks(NULL, FALSE);
597
//        //achain_dealloc(&board_root, board_mem);
598
//        achain_dealloc(&aimoves_root, aimoves_mem);
599
//        //board_size = size;
600
//        //board_stride = size + 2;
601
//        //board_mem = sizeof (Board) + board_stride * board_stride *
602
//        //            sizeof (PIECE);
603
//        aimoves_mem = sizeof (AIMoves) + size * size * sizeof (AIMove);
604
//}
605
 
606
//Board *board_at(unsigned int move)
607
//{
608
//        if (move >= history->len)
609
//                return NULL;
610
//        return (Board*)g_ptr_array_index(history, move);
611
//}
612
 
613
int count_pieces(const Board *b, BCOORD x, BCOORD y, PIECE type, int dx, int dy,
614
                 PIECE *out)
615
{
616
        int i;
617
        PIECE p = PIECE_NONE;
618
 
619
        if (!dx && !dy)
620
                return piece_at(b, x, y) == type ? 1 : 0;
621
        for (i = 0; x >= 0 && x < board_size && y >= 0 && y < board_size; i++) {
622
                p = piece_at(b, x, y);
623
                if (p != type)
624
                        break;
625
                x += dx;
626
                y += dy;
627
        }
628
        /* this two lines create problem in synthesis  preprocess ?? */
629
        if (out)
630
                *out = p;
631
        return i;
632
}
633
 
634
gboolean check_win_full(const Board *b, BCOORD x, BCOORD y,
635
                        BCOORD *x1, BCOORD *y1, BCOORD *x2, BCOORD *y2)
636
{
637
        int i, c1, c2, xs[] = {1, 1, 0, -1}, ys[] = {0, 1, 1, 1};
638
        PIECE type;
639
        PIECE p;
640 18 sumanta.ch
        if(x<0 || y<0) return FALSE;
641 17 sumanta.ch
        type = piece_at(b, x, y);
642
        if (type != PIECE_BLACK && type != PIECE_WHITE)
643
                return FALSE;
644
        for (i = 0; i < 4; i++) {
645
                c1 = count_pieces(b, x, y, type, xs[i], ys[i], &p);
646
                c2 = count_pieces(b, x, y, type, -xs[i], -ys[i], &p);
647
                if (c1 + c2 > connect_k) {
648
                        //if (x1)
649
                        //        *x1 = x + xs[i] * (c1 - 1);
650
                        //if (y1)
651
                        //        *y1 = y + ys[i] * (c1 - 1);
652
                        //if (x2)
653
                        //        *x2 = x - xs[i] * (c2 - 1);
654
                        //if (y2)
655
                        //        *y2 = y - ys[i] * (c2 - 1);
656
                        return TRUE;
657
                }
658
        }
659
        return FALSE;
660
}
661
 
662
///* Convert a boord coordinate to alpha representation */
663
//const char *bcoord_to_alpha(BCOORD x)
664
//{
665
//        static char buf[2][32];
666
//        static int which;
667
//        int i, divisor = 26;
668
//
669
//        which = !which;
670
//        for (i = 0; i < sizeof (buf[which]) - 1; i++) {
671
//                div_t result;
672
//
673
//                result = div(x, divisor);
674
//                buf[which][i] = 'a' + result.rem * 26 / divisor;
675
//                if (i)
676
//                        buf[which][i]--;
677
//                x -= result.rem;
678
//                if (!x)
679
//                        break;
680
//                divisor *= 26;
681
//        }
682
//        buf[which][i + 1] = 0;
683
//        return g_strreverse(buf[which]);
684
//}
685
 
686
//// Get a string representation of board x/y coordinates (d7, h16, etc)
687
//const char *bcoords_to_string(BCOORD x, BCOORD y)
688
//{
689
//        static char buf[2][32];
690
//        static int which;
691
//
692
//        which = !which;
693
//        g_snprintf(buf[which], sizeof (buf[which]), "%s%d",
694
//                   bcoord_to_alpha(x), board_size - y);
695
//        return buf[which];
696
//}
697
//
698
/* Convert a string representation to coordinates */
699
void string_to_bcoords(const char *str, BCOORD *x, BCOORD *y)
700
{
701
        *x = 0;
702
        *y = 0;
703
        while (*str && *str >= 'a' && *str <= 'z') {
704
                *x *= 26;
705
                *x += *str - 'a';
706
                str++;
707
        }
708
        while (*str && *str >= '0' && *str <= '9') {
709
                *y *= 10;
710
                *y += *str - '0';
711
                str++;
712
        }
713
        if (*y)
714
                *y = board_size - *y;
715
}
716
 
717
const char *piece_to_string(PIECE piece)
718
{
719
        switch (piece) {
720
        case PIECE_WHITE:
721
                return "White";
722
        case PIECE_BLACK:
723
                return "Black";
724
        case PIECE_NONE:
725
                return "None";
726
        case PIECE_ERROR:
727
                return "Error";
728
        default:
729
                return "Mark";
730
        }
731
}
732
 
733
char piece_to_char(PIECE piece)
734
{
735
        switch (piece) {
736
        case PIECE_WHITE:
737
                return 'W';
738
        case PIECE_BLACK:
739
                return 'B';
740
        case PIECE_NONE:
741
                return '_';
742
        case PIECE_ERROR:
743
                return 'E';
744
        default:
745
                return 'M';
746
        }
747
}
748
 
749
//char *search_to_string(SEARCH s)
750
//{
751
//        switch (s) {
752
//        case SEARCH_NONE:
753
//                return "No search";
754
//        case SEARCH_DFS:
755
//                return "Depth first search";
756
//        case SEARCHES:
757
//                break;
758
//        }
759
//        return "Unknown";
760
//}
761
 
762
//void go_to_move(unsigned int move)
763
//{
764
//        Board board2;
765
//
766
//        if (!history)
767
//                history = g_ptr_array_sized_new(32);
768
//        if (move > history->len)
769
//                move = history->len;
770
//        if (move == history->len) {
771
//                //board2 = board_new();
772
//                if (&board)
773
//                        board_copy(&board, &board2);
774
//                g_ptr_array_add(history, &board2);
775
//                board2.parent = &board;
776
//        } else
777
//                //board2 = (Board*)g_ptr_array_index(history, move);
778
//        //&board = &board2;
779
//        move_no = move;
780
//        if (move_no > move_last)
781
//                move_last = move_no;
782
//}
783
 
784
//void clear_history(unsigned int from)
785
//{
786
//        int i;
787
//
788
//        if (!history)
789
//                return;
790
//        if (from >= history->len) {
791
//                g_warning("Attempted to clear future history");
792
//                return;
793
//        }
794
//        for (i = from; i < history->len; i++)
795
//                board_free(g_ptr_array_index(history, i));
796
//        g_ptr_array_remove_range(history, from, history->len - from);
797
//        move_last = from;
798
//}
799
/* Clear the board and history for a new game */
800
void new_game(Board *board,unsigned int size)
801
{
802
        //tree_view_clear(1);
803
        //clear_history(0);
804
        //set_board_size(size);
805
        //board = NULL;
806
        //go_to_move(0);
807
        //move_last=0;
808
        //move_no=0;
809
        board_init(board);
810
        board->moves_left = start_q;
811
        board->turn = PIECE_BLACK;
812
        //draw_board();
813
        //stop_ai();
814
        //setup_move();
815
}
816
void board_copy(const Board *from, Board *to){
817
int i,j;
818
for(i=0;i<board_stride;i++)
819
        for(j=0;j<board_stride;j++)
820
                to->data[i][j]=from->data[i][j];
821
 
822
        to->ac= from->ac;
823
        to->moves_left= from->moves_left;
824
        to->parent =    from->parent;
825
        to->won    =    from->won;
826
        to->win_x1 =    from->win_x1;
827
        to->win_y1 =    from->win_y1;
828
        to->win_x2 =    from->win_x2;
829
        to->win_y2 =    from->win_y2;
830
        to->turn   =    from->turn;
831
        to->move_x =    from->move_x;
832
        to->move_y =    from->move_y;
833
 
834
 
835
}

powered by: WebSVN 2.1.0

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