-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChessParser.h
97 lines (82 loc) · 2.22 KB
/
ChessParser.h
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
/*
* Parser.h
*
* Created on: Feb 25, 2018
* Author: krimolovsky
*/
#ifndef CHESSPARSER_H_
#define CHESSPARSER_H_
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define COMMAND_LENGTH 2000
//a type used to represent a command
typedef enum {
CHESS_GAME_MODE,
CHESS_DIFFICULTY,
CHESS_USER_COLOR,
CHESS_LOAD,
CHESS_DEFAULT,
CHESS_PRINT_SETTINGS,
CHESS_QUIT,
CHESS_START,
CHESS_MOVE,
CHESS_GET_MOVES,
CHESS_SAVE,
CHESS_UNDO,
CHESS_RESET,
CHESS_INVALID,
} CHESS_COMMAND;
//a new type that is used to encapsulate a parsed line
typedef struct command_t {
CHESS_COMMAND cmd;
char path[COMMAND_LENGTH];
char to[2];
char from[2];
int number;
} CHESSCommand;
/*
* Checks if a specified string represents a valid integer. It is recommended
* to use this function prior to calling the standard library function atoi.
*
* @return
* true if the string represents a valid integer, and false otherwise.
*/
bool parserIsInt(const char* str);
/*
* this function receives a string and by comparing the string meaning, it returns the appropriate enum_command value.
*
* @returns
* the enum_command that cmd is it's name
* if the string is not a valid name of enum_command, CHESS_INVALID
*/
CHESS_COMMAND spParserPraseLineHelper(char *cmd);
/*
*this function is called from the settings window in the game.
*@returns
*the command that was received from the user.
*if the command is invalid, then CHESSCommand is INVALID.
*/
CHESSCommand parserSettingsParseLine(const char* str);
/*
* this function receives a string and by comparing the string meaning, it returns the appropriate enum_command value.
*
* @returns
* the enum_command that cmd is it's name
* if the string is not a valid name of enum_command, CHESS_INVALID
*/
CHESS_COMMAND parserGameParseLineHelper(char* arg1);
/*
*this function is called from the game window in the game.
*@returns
*the command that was received from the user.
*if the command is invalid, then CHESSCommand is INVALID.
*/
CHESSCommand parserGameParseLine(const char* str);
/*
* checks if arg2 is like the pattern <x,y>, for x and y KOLSHEHEM
*/
bool parserCoordinates(char *arg2);
void printCHESSCOMMAND(CHESSCommand command);
#endif /* CHESSPARSER_H_ */