Task 02: git task#92
Conversation
|
@marynamalakhova, what's the purpose of picking 12e9e40 (as 9cdd359) instead of basing the branch on top of bd00000? |
|
Please use enums instead of digits and separate resources (matrix, strings, etc.) from logic (define in different source files). |
011ef33 to
a2a404c
Compare
|
Opened another PR |
214ccac to
8bbc515
Compare
AleksandrBulyshchenko
left a comment
There was a problem hiding this comment.
@marynamalakhova,
Please see my comments below.
Also please note that the fixes should be made inplace (in the patches where the issues are appear).
scissors/scissors_game/scissors.h
Outdated
| const int game_table[3][3]={ | ||
| eDRAW, eLOST, eWINN, | ||
| eWINN, eDRAW, eLOST, | ||
| eLOST, eWINN, eDRAW | ||
| }; |
There was a problem hiding this comment.
You shouldn't define variables in header files.
This will lead to error in case of it's inclusion in more than one source file (which is actually what headers are for).
The table should be moved into separate source file.
Together with function for comparison (and probably function for parsing as well).
8dfc498 to
e237ba7
Compare
|
Thank you for review. I've fixed |
AleksandrBulyshchenko
left a comment
There was a problem hiding this comment.
Current separation into modules is mostly meaningful.
(All the code is actually moved together and main just call single function in a loop.)
Please provide real separation:
- all input / output should be separated from the game logic (e.g. remain in the main module);
- game logic should implement separate functions for:
- user value (transform user input into enum);
- comp value (returns randomly generated enum);
- result calculation (gets two values and returns a result;
Also see few comments inline.
220cce0 to
46cf741
Compare
|
Thank you for review. I`ve already fixed. |
Add main file with initial output (according to task02). Add Makefile. Signed-off-by: Maryna Malakhova <maryna.malakhova@globallogic.com>
7f85ddb to
64021cb
Compare
scissors/scissors_game/scissors.h
Outdated
| static const char * const Game_Elements[] = { | ||
| "unknown", "rock", "paper", "scissors"}; | ||
| static enum { | ||
| UNKNOWN, | ||
| ROCK, | ||
| PAPER, | ||
| SCISSORS | ||
| } element_id; |
There was a problem hiding this comment.
Variable definitions (and thus - memory allocation) in header!
What's the purpose of element_id at all? - Most probably you've meant something different.
| case 's': | ||
| ans = SCISSORS; | ||
| } |
There was a problem hiding this comment.
Case without break - high probability of error in case of extention.
| res = char_to_element_index(input); | ||
| if (!res) | ||
| printf("You've chosen something strange!\n"); |
There was a problem hiding this comment.
char_to_element_index() in case of error returns UNKNOWN, but return value is compared to 0.
Currently UNKNOWN == 0, but this isn't guaranteed in case of modification. If return values have exact meaning, it's comparison should be explicit.
scissors/scissors_game/scissors.h
Outdated
| PAPER, | ||
| SCISSORS | ||
| } element_id; | ||
| int play_scissors(void); |
There was a problem hiding this comment.
play_scissors() is declared in 5ea78fe, but not defined.
| int play_scissors(void) | ||
| { | ||
| return (rand()%3)+1; | ||
| } |
There was a problem hiding this comment.
Definitions order in source file and declarations order in header should be aligned.
| case DRAW: | ||
| printf("It's draw\n"); | ||
| } |
scissors/scissors_game/scissors.c
Outdated
| /* rock paper scissors */ | ||
| /* rock*/ DRAW, LOST, WINN, | ||
| /* paper*/ WINN, DRAW, LOST, | ||
| /* sciss*/ LOST, WINN, DRAW |
There was a problem hiding this comment.
Please whenever possible avoid mixing tabs and spaces for indentation.
scissors/scissors_game/scissors.c
Outdated
|
|
||
| int get_game_result(int user, int comp) | ||
| { | ||
| return game_table[user-1][comp-1]; |
There was a problem hiding this comment.
Using enum instead of 1 will make code more robust.
scissors/scissors_game/scissors.h
Outdated
| static enum { | ||
| DRAW, | ||
| LOST, | ||
| WINN | ||
| } game_results; |
There was a problem hiding this comment.
What's the purpose of variable game_results? - Most probably you've meant something different.
1678de6 to
28ece96
Compare
Add users input reading and printing if it is a wrong one Signed-off-by: Maryna Malakhova <maryna.malakhova@globallogic.com>
Init random. Add new random decision of the computer's choise. Finish intermidiate output. Signed-off-by: Maryna Malakhova <maryna.malakhova@globallogic.com>
Add table an function in order to get the winner Add game result output Signed-off-by: Maryna Malakhova <maryna.malakhova@globallogic.com>
28ece96 to
889a3cc
Compare
|
Thank you for review, I`ve fixed. |
Add game "scissors". Used matrix for getting decision to find the winner.