summaryrefslogtreecommitdiffstats
path: root/modules/xyzzy/src/xyzzy.c
blob: 4e0cb66b9de07f97196037b673699b4031b47384 (plain) (blame)
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
/******************************************************************************
 *	Copyright (C) 2018	Alejandro Colomar Andrés		      *
 ******************************************************************************/


/******************************************************************************
 ******* headers **************************************************************
 ******************************************************************************/
	#include <stdbool.h>

	#include "game_iface.h"

	#include "xyzzy.h"


/******************************************************************************
 ******* variables ************************************************************
 ******************************************************************************/
static	int	x;
static	bool	step_notflag;


/******************************************************************************
 ******* static functions *****************************************************
 ******************************************************************************/
static	void	xyzzy_step_all	(const struct Game_Iface_Out	*out,
				struct Game_Iface_In		*in);
static	void	xyzzy_flag_all	(const struct Game_Iface_Out	*out,
				struct Game_Iface_In		*in);


/******************************************************************************
 ******* main *****************************************************************
 ******************************************************************************/
void	xyzzy_init	(void)
{

	x		= 0;
	step_notflag	= true;
}

int	xyzzy_lin	(const struct Game_Iface_Out	*out,
			struct Game_Iface_In		*in)
{

	if (!x)
		x	= 1;

	if (step_notflag) {
		xyzzy_step_all(out, in);
	} else {
		xyzzy_flag_all(out, in);
		x--;
	}

	step_notflag	= !step_notflag;

	return	x;
}

int	xyzzy_p		(const struct Game_Iface_Out	*out,
			struct Game_Iface_In		*in)
{

	if (!x)
		x	= (out->rows * out->cols) / 2;

	xyzzy_lin(out, in);

	return	x;
}


/******************************************************************************
 ******* static functions *****************************************************
 ******************************************************************************/
static	void	xyzzy_step_all	(const struct Game_Iface_Out	*out,
				struct Game_Iface_In		*in)
{
	int	i;
	int	j;

	for (i = 0; i < out->rows; i++) {
	for (j = 0; j < out->cols; j++) {
		if (out->usr[i][j] == GAME_IFACE_USR_CLEAR)
			in->act_game[i][j]	= GAME_IFACE_GAME_ACT_STEP;
	}
	}
}

static	void	xyzzy_flag_all	(const struct Game_Iface_Out	*out,
				struct Game_Iface_In		*in)
{
	int	i;
	int	j;

	for (i = 0; i < out->rows; i++) {
	for (j = 0; j < out->cols; j++) {
		if (out->usr[i][j] == GAME_IFACE_USR_CLEAR)
			in->act_game[i][j]	= GAME_IFACE_GAME_ACT_FLAG;
	}
	}
}


/******************************************************************************
 ******* end of file **********************************************************
 ******************************************************************************/