forked from giuliano-ippoliti/GiuChess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.c
174 lines (144 loc) · 3.63 KB
/
list.c
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
// This file is a part of the GiuChess Project.
//
// Copyright (c) 2005 Giuliano Ippoliti aka JSorel (ippo@linuxmail.org)
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "list.h"
void crt_list(MOVE_LIST *lst)
{
*lst = NULL;
}
int list_void(MOVE_LIST *lst)
{
return (lst == NULL);
}
void *ins_head(MOVE_LIST *new_lst, int order, char color, char newpiece, BITMASK bm_move, MOVE_LIST old_lst) //new_list is modified
{
MOVE_LIST tmp_lst;
tmp_lst = (MOVE_LIST)malloc(sizeof(MOVE_LEG));
if (tmp_lst != NULL)
{
tmp_lst->order = order;
tmp_lst->color = color;
tmp_lst->newpiece = newpiece;
tmp_lst->bm_move = bm_move;
tmp_lst->next = old_lst;
*new_lst = tmp_lst;
}
return (tmp_lst);
}
void canc_list1(MOVE_LIST *lst)
{
MOVE_LIST tmp_lst;
while (*lst != NULL)
{
tmp_lst = *lst;
*lst = tmp_lst->next;
free(tmp_lst);
}
}
void canc_list(MOVE_LIST *lst)
{
MOVE_LIST tmp_lst;
if (*lst != NULL)
{
tmp_lst = (*lst)->next;
free(*lst);
canc_list(&tmp_lst);
*lst = NULL;
}
}
void print_lst(MOVE_LIST lst)
{
MOVE_LIST tmp_lst;
tmp_lst = lst;
while (tmp_lst != NULL)
{
printf("%c\n", tmp_lst->color);
tmp_lst = tmp_lst->next;
}
}
void log_lst(MOVE_LIST lst)
{
MOVE_LIST tmp_lst;
char move[6];
int order;
char color, newpiece;
int oldrow, oldcol, newrow, newcol;
BITMASK bm_old, bm_new;
tmp_lst = lst;
while (tmp_lst != NULL)
{
order = tmp_lst->order;
color = tmp_lst->color;
newpiece = tmp_lst->newpiece;
bm_new = tmp_lst->bm_move;
if (color == 'W')
bm_old = w[order].bm_pos;
else
bm_old = b[order].bm_pos;
conv_bm_cases(bm_old, &oldrow, &oldcol);
conv_bm_cases(bm_new, &newrow, &newcol);
move[0] = 97 + oldcol;
move[1] = 49 + oldrow;
move[2] = 97 + newcol;
move[3] = 49 + newrow;
if (newpiece == '-')
move[4] = '\0';
else
{
move[4] = newpiece;
move[5] = '\0';
}
llog("%s\n", move);
tmp_lst = tmp_lst->next;
}
}
void log_lst2(MOVE_LIST lst)
{
MOVE_LIST tmp_lst;
char move[6];
int order;
char color, newpiece;
int oldrow, oldcol, newrow, newcol;
BITMASK bm_old, bm_new;
tmp_lst = lst;
while (tmp_lst != NULL)
{
order = tmp_lst->order;
color = tmp_lst->color;
newpiece = tmp_lst->newpiece;
bm_new = tmp_lst->bm_move;
if (color == 'W')
bm_old = w[order].bm_pos;
else
bm_old = b[order].bm_pos;
conv_bm_cases(bm_old, &oldrow, &oldcol);
conv_bm_cases(bm_new, &newrow, &newcol);
move[0] = 97 + oldcol;
move[1] = 49 + oldrow;
move[2] = 97 + newcol;
move[3] = 49 + newrow;
if (newpiece == '-')
move[4] = '\0';
else
{
move[4] = newpiece;
move[5] = '\0';
}
llog("%s %f\n", move, tmp_lst->evaluation);
tmp_lst = tmp_lst->next;
}
}