#Queen Atack

53 messages · Page 1 of 1 (latest)

eager flare
#

hello I can’t find the error in my code to pass the first test in Queen Attack can you help me find the error:track_c

true ember
#

Hello 👋
If you post the code, you already wrote, in a code block it is much, much easier to read 😉
FYI: Code blocks are 3x backticks before and after the code

eager flare
#

what??😭

true ember
#

If you have code you can paste it like this

int a = 5

by wrapping the text in 3x backticks (one set of 3 before and one set of 3 after the text)

eager flare
#

I do not see the contribution with the error of my code 😅

wary charmBOT
#

Increase your chance of getting help and look like a pro by sharing codeblocks not images. For example, you can type the following. Note, the ``` must be on their own line.
```
for number in range(10):
total += number;
```
Discord will render that as so:

for number in range(10):
    total += number;

Click here to learn more about codeblocks, including how to indicate the programming language: https://exercism.org/docs/community/being-a-good-community-member/writing-support-requests and http://bit.ly/howto-ask

tranquil cosmos
#

There are people here using screen readers who cannot view images

true ember
#

See if you post the code just as a screenshot I'd have to make a ton of assumptions what your code does. Like which values the constants have and such. If you paste the entire code it is much easier to find out what went wrong 🙂

tranquil cosmos
#

It's also pretty hard to copy/paste your code to test it out when it's an image 😉 Code is text. Share text as text

#

And, preferably, the whole file

eager flare
#

attack_status_t can_attack(position_t queen_1, position_t queen_2) {
    if (queen_1.row > 7 || queen_1.column > 7 || queen_2.row > 7 || queen_2.column > 7) {
        return INVALID_POSITION;
    }

    int diff_row = (int)queen_1.row - (int)queen_2.row;
    int diff_column = (int)queen_1.column - (int)queen_2.column;

    if (diff_row < 0) diff_row = -diff_row;
    if (diff_column < 0) diff_column = -diff_column;

    if (queen_1.row == queen_2.row || queen_1.column == queen_2.column || diff_row == diff_column) {
        return CAN_ATTACK;
    } else {
        return CAN_NOT_ATTACK;
    }
} ```
true ember
#

If you apply the formating via code blocks the discord formating of || won't make spoilers 🙂

tranquil cosmos
#

Can you edit your last post and put a ``` before and after your code, @eager flare ?

eager flare
#

like that*

tranquil cosmos
#

Yes! Thank you. Could you also share the header file?

#

The code references values not defined in the file 🙂

eager flare
#
#define QUEEN_ATTACK_H

#include <stdint.h>

typedef enum { CAN_NOT_ATTACK, CAN_ATTACK, INVALID_POSITION } attack_status_t;

typedef struct {
   uint8_t row;
   uint8_t column;
} position_t;

attack_status_t can_attack(position_t queen_1, position_t queen_2);

#endif
tranquil cosmos
#

Awesome. How about the failing test details, also in a codeblock?

eager flare
#

test 1:Test Failure

Expected 2 Was 1

Your Output

./

tranquil cosmos
#

Cool. Do you understand that Expected line?

eager flare
#

he wants CAN_ATTACK to return 2 while the one returns 1

tranquil cosmos
#

can_attack, not CAN_ATTACK.

#

Do you know what 1 and 2 represent?

eager flare
#

this corresponds to the value in my enum attack_status_t

tranquil cosmos
#

Right

#

So ... do you understand what's wrong here?

#

The test name has a hint as to what is being tested

eager flare
#

yes it sent CAN_NOT_ATTACK back instead ofCAN_ATTACK

tranquil cosmos
#

What's 1 and 2 in the enum?

modern bramble
#

Apart from what Isaac is saying, another hint is to look at the name of the failing test. It usually specifies what is being tested.

#

ow, Isaac already said that 🙂

tranquil cosmos
#

@eager flare ?

eager flare
#

yes but I really don’t see the mistake

tranquil cosmos
#

What's 1 and 2 in the enum?

eager flare
#

CAN_NOT_ATTACK, CAN_ATTACK

tranquil cosmos
#

I don't think that's correct

#

What's the integer value that enums start at?

eager flare
#

0

#

0 is:I don't think that's correct 1:CAN_ATTACK and 2:INVALID_POSITION

tranquil cosmos
#

That sounds more correct

#

So what is the test expecting and what is your code returning?

eager flare
#

I have to get back :iNVALID_POSITION and my code return :CAN_ATTACK

tranquil cosmos
#

Right. Did you see the test name? Do you understand what case is being tested and why it is invalid?

eager flare
#

Yess I understand

tranquil cosmos
#

👍

#

Then do you know how to fix that issue?

eager flare
#

No 🦧🦧

tranquil cosmos
#

I have to get back :iNVALID_POSITION and my code return :CAN_ATTACK

  • Do you understand what is being tested?
  • Do you understand why iNVALID_POSITION is the expected value?
  • Do you understand why your code returns CAN_ATTACK?
eager flare
#

I know why but I don't see the error in my code

modern bramble
#

The name of the failing test is "invalid_if_on_same_position"

tranquil cosmos
#

Why do the tests expect invalid? Why doesn't the code return invalid? Can you fix that?

eager flare
#

I understood what was asked of me, but I don't see where the mistake is.