Skip to content

Task 02: git task#92

Open
marynamalakhova wants to merge 4 commits intoKernel-GL-HRK:Maryna.Malakhovafrom
marynamalakhova:task_scissors
Open

Task 02: git task#92
marynamalakhova wants to merge 4 commits intoKernel-GL-HRK:Maryna.Malakhovafrom
marynamalakhova:task_scissors

Conversation

@marynamalakhova
Copy link

@marynamalakhova marynamalakhova commented Mar 10, 2021

Add game "scissors". Used matrix for getting decision to find the winner.

@AleksandrBulyshchenko
Copy link

@marynamalakhova, what's the purpose of picking 12e9e40 (as 9cdd359) instead of basing the branch on top of bd00000?

@AleksandrBulyshchenko
Copy link

Please use enums instead of digits and separate resources (matrix, strings, etc.) from logic (define in different source files).

@marynamalakhova marynamalakhova force-pushed the task_scissors branch 2 times, most recently from 011ef33 to a2a404c Compare March 11, 2021 17:25
@marynamalakhova
Copy link
Author

Opened another PR

Copy link

@AleksandrBulyshchenko AleksandrBulyshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marynamalakhova,
Please see my comments below.

Also please note that the fixes should be made inplace (in the patches where the issues are appear).

Comment on lines +14 to +21
const int game_table[3][3]={
eDRAW, eLOST, eWINN,
eWINN, eDRAW, eLOST,
eLOST, eWINN, eDRAW
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@AleksandrBulyshchenko AleksandrBulyshchenko added Change requested Change requested and removed Ready for review Ready for review labels Mar 22, 2021
@marynamalakhova marynamalakhova force-pushed the task_scissors branch 5 times, most recently from 8dfc498 to e237ba7 Compare March 24, 2021 10:15
@marynamalakhova marynamalakhova added the Ready for review Ready for review label Mar 24, 2021
@marynamalakhova
Copy link
Author

Thank you for review. I've fixed

@marynamalakhova marynamalakhova removed the Change requested Change requested label Mar 25, 2021
Copy link

@AleksandrBulyshchenko AleksandrBulyshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AleksandrBulyshchenko AleksandrBulyshchenko added Change requested Change requested and removed Ready for review Ready for review labels Apr 2, 2021
@marynamalakhova marynamalakhova force-pushed the task_scissors branch 2 times, most recently from 220cce0 to 46cf741 Compare April 2, 2021 08:55
@marynamalakhova
Copy link
Author

Thank you for review. I`ve already fixed.

@marynamalakhova marynamalakhova added Ready for review Ready for review and removed Change requested Change requested labels Apr 2, 2021
Add main file with initial output (according to task02).
Add Makefile.

Signed-off-by: Maryna Malakhova <maryna.malakhova@globallogic.com>
@marynamalakhova marynamalakhova force-pushed the task_scissors branch 2 times, most recently from 7f85ddb to 64021cb Compare April 5, 2021 13:24
Comment on lines +2 to +9
static const char * const Game_Elements[] = {
"unknown", "rock", "paper", "scissors"};
static enum {
UNKNOWN,
ROCK,
PAPER,
SCISSORS
} element_id;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable definitions (and thus - memory allocation) in header!

What's the purpose of element_id at all? - Most probably you've meant something different.

Comment on lines +15 to +33
case 's':
ans = SCISSORS;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case without break - high probability of error in case of extention.

Comment on lines +14 to +21
res = char_to_element_index(input);
if (!res)
printf("You've chosen something strange!\n");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

PAPER,
SCISSORS
} element_id;
int play_scissors(void);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

play_scissors() is declared in 5ea78fe, but not defined.

int play_scissors(void)
{
return (rand()%3)+1;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitions order in source file and declarations order in header should be aligned.

Comment on lines +33 to +39
case DRAW:
printf("It's draw\n");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case without break!

Comment on lines +13 to +16
/* rock paper scissors */
/* rock*/ DRAW, LOST, WINN,
/* paper*/ WINN, DRAW, LOST,
/* sciss*/ LOST, WINN, DRAW

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please whenever possible avoid mixing tabs and spaces for indentation.


int get_game_result(int user, int comp)
{
return game_table[user-1][comp-1];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using enum instead of 1 will make code more robust.

Comment on lines +11 to +15
static enum {
DRAW,
LOST,
WINN
} game_results;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of variable game_results? - Most probably you've meant something different.

@AleksandrBulyshchenko AleksandrBulyshchenko added Change requested Change requested and removed Ready for review Ready for review labels Apr 5, 2021
@marynamalakhova marynamalakhova force-pushed the task_scissors branch 2 times, most recently from 1678de6 to 28ece96 Compare April 6, 2021 07:43
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>
@marynamalakhova marynamalakhova added Ready for review Ready for review and removed Change requested Change requested labels Apr 6, 2021
@marynamalakhova
Copy link
Author

Thank you for review, I`ve fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants