-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwaste.c
More file actions
executable file
·85 lines (74 loc) · 2.05 KB
/
waste.c
File metadata and controls
executable file
·85 lines (74 loc) · 2.05 KB
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
/* waste.c */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <raylib.h>
#include "baize.h"
#include "pile.h"
#include "array.h"
#include "constraint.h"
#include "waste.h"
static struct PileVtable wasteVtable = {
&WasteCanMoveTail,
&WasteCanAcceptCard,
&WasteCanAcceptTail,
&GenericTailTapped,
&WasteCollect,
&WasteComplete,
&PileGenericUnsortedPairs,
&PileReset,
&PileUpdate,
&PileDraw,
&PileFree,
};
struct Waste* WasteNew(struct Baize *const baize, Vector2 slot, enum FanType fan)
{
struct Waste* self = calloc(1, sizeof(struct Waste));
if ( self ) {
PileCtor(baize, (struct Pile*)self, "Waste", slot, fan);
self->super.vtable = &wasteVtable;
}
return self;
}
_Bool WasteCanMoveTail(struct Array *const tail)
{
if (ArrayLen(tail)>1) {
struct Card *c = ArrayGet(tail, 0);
struct Baize *baize = PileOwner(CardOwner(c));
BaizeSetError(baize, "(CSOL) Only a single card can be moved from Waste");
return 0;
}
return 1;
}
_Bool WasteCanAcceptCard(struct Baize *const baize, struct Pile *const self, struct Card *const c)
{
struct Pile *src = CardOwner(c);
if (src != baize->stock) {
BaizeSetError(baize, "(CSOL) Can only move cards to Waste from Stock");
return 0;
}
struct Array1 tail = Array1New(c);
return CanTailBeAppended(self, (struct Array*)&tail);
// don't need to free an Array1
}
_Bool WasteCanAcceptTail(struct Baize *const baize, struct Pile *const self, struct Array *const tail)
{
if (ArrayLen(tail) == 1) {
return WasteCanAcceptCard(baize, self, ArrayGet(tail, 0));
}
struct Card *c = ArrayGet(tail, 0);
struct Pile *src = CardOwner(c);
if (src != baize->stock) {
BaizeSetError(baize, "(CSOL) Can only move cards to Waste from Stock");
return 0;
}
return CanTailBeAppended(self, tail);
}
int WasteCollect(struct Pile *const self)
{
return PileGenericCollect(self);
}
_Bool WasteComplete(struct Pile *const self)
{
return PileEmpty(self);
}