8 typedef struct fifo_node
{
10 struct fifo_node
*prev
;
13 static fifo_node
*tower_entrance
= NULL
;
14 static fifo_node
*tower_exit
= NULL
;
16 struct ast
*const_true
;
17 struct ast
*const_false
;
18 DATA knights
[KNIGHT_NUM
+ 1];
20 void tower_push(DATA
* d
)
24 if (!tower_entrance
) {
25 tower_entrance
= malloc(sizeof (fifo_node
));
26 if (!tower_entrance
) {
27 fprintf(stderr
, "Fatal: Could not allocate memory for tower\n");
31 tower_exit
= tower_entrance
;
32 tower_entrance
->data
= d
;
33 tower_entrance
->prev
= NULL
;
35 new_node
= malloc(sizeof (fifo_node
));
37 fprintf(stderr
, "Fatal: Could not allocate memory for tower\n");
42 new_node
->prev
= NULL
;
43 tower_entrance
->prev
= new_node
;
44 tower_entrance
= new_node
;
50 DATA
*to_return
= NULL
;
56 to_return
= tower_exit
->data
;
58 if (tower_entrance
== tower_exit
) {
60 tower_entrance
= NULL
;
63 to_delete
= tower_exit
;
64 tower_exit
= tower_exit
->prev
;
76 for (idx
= 1; idx
<= KNIGHT_NUM
; ++idx
) {
77 tidx
= 1 + rand() % KNIGHT_NUM
;
79 knights
[tidx
] = knights
[idx
];
84 void tower_initialize()
88 const_true
= malloc(sizeof (ast
));
89 const_true
->type
= A_VAR
;
90 const_true
->adata
.avar
= malloc(sizeof (ast_var
));
91 const_true
->adata
.avar
->type
= COMPUTED_VAL
;
92 const_true
->adata
.avar
->val
.computed_val
.type
= KBOOL
;
93 const_true
->adata
.avar
->val
.computed_val
.val
= 1;
95 const_false
= malloc(sizeof (ast
));
96 const_false
->type
= A_VAR
;
97 const_false
->adata
.avar
= malloc(sizeof (ast_var
));
98 const_false
->adata
.avar
->type
= COMPUTED_VAL
;
99 const_false
->adata
.avar
->val
.computed_val
.type
= KBOOL
;
100 const_false
->adata
.avar
->val
.computed_val
.val
= 0;
102 for (i
= 1; i
<= 9; ++i
) {
103 knights
[i
].type
= KINT
;