Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should sector's be created on the server? #73

Open
RowanHarley opened this issue Aug 17, 2016 · 15 comments
Open

How should sector's be created on the server? #73

RowanHarley opened this issue Aug 17, 2016 · 15 comments

Comments

@RowanHarley
Copy link
Contributor

How should I go about creating the sector's for my slither server? Should I create them all at once and if so, do each of them need ID's?

@Mat2095
Copy link
Collaborator

Mat2095 commented Aug 17, 2016

You probably don't need IDs, since the x and y coordinates of a sector should identify it.
Creating them all at once would probably make most sense, or would that take too long?

@RowanHarley
Copy link
Contributor Author

Would I need the x and y of 2 point's or just 1? I'm thinking 2 because that would be the only way to identify whether the player is inside the sector

@Mat2095
Copy link
Collaborator

Mat2095 commented Aug 18, 2016

All sectors have the same width and height, so one coordinate would be enough.

@RowanHarley
Copy link
Contributor Author

How should I go about creating the sector's? Should I add sector_count_along_edge and sector_size to the equation?

@Mat2095
Copy link
Collaborator

Mat2095 commented Aug 18, 2016

for (y = 0; y < sector_count_along_edge; y++) {
    for (x = 0; x < sector_count_along_edge; x++) {
        createSector(x, y);
    }
}

In createSector you create a sector that goes from x * sector_size (inclusive) to (x+1) * sector_size (exclusive), the same for y. Keep in mind that coordinates of food/prey/snakes might not be integer.

@RowanHarley
Copy link
Contributor Author

Ok, thank's! I'll try implement something like that

@RowanHarley
Copy link
Contributor Author

RowanHarley commented Aug 23, 2016

Ok, so I've used your code to make the sector's and store them in an array but I'm not sure how to check which sector the snake is inside. Sorry for taking so long to reply. I had problems with my internet for a while

@Mat2095
Copy link
Collaborator

Mat2095 commented Aug 23, 2016

You're using a two-dimensional array I guess?

@RowanHarley
Copy link
Contributor Author

No, I'm using a one-dimensional array of Sector()'s. Each one holds the start x, start y, end x and end y.

@Mat2095
Copy link
Collaborator

Mat2095 commented Aug 24, 2016

Use a two dimensional array. That way you can just get the sector with sectors[(int)(snake.y / sector_size)][(int)(snake.x / sector_size)] or similar and don't have to go through all of them to find the correct one (which would probably take too long).

@RowanHarley
Copy link
Contributor Author

I'm not sure I understand. So should each sector have just x * sector_size and y * sector_size? Do I need (x + 1) * sector_size and (y +1) * sector_size?

@Mat2095
Copy link
Collaborator

Mat2095 commented Aug 24, 2016

Let's say you have x * sector_size as sector_x_start. You CAN have sector_x_end (as (x+1) * sector_size), but you don't have to because you can easily get it when needed: sector_x_end = sector_x_start + sector_size.

If you need sector_x_end very often, it can be a good idea to have it, but if you don't need it often, just use sector_x_start + sector_size instead.

@RowanHarley
Copy link
Contributor Author

Ok, now I get you. Thanks I'll try implement it that way then

@Mat2095
Copy link
Collaborator

Mat2095 commented Sep 9, 2016

Any updates?

@RowanHarley
Copy link
Contributor Author

I'm finding it hard to update this project this year. I'm currently in junior cert (exam year) so need to spend some time studying and homework

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

No branches or pull requests

3 participants