Checkers game, getting the piece i've jumped overs location

  • Thread starter Thread starter Dave2041
  • Start date Start date
  • Tags Tags
    Game
AI Thread Summary
In a discussion about implementing a checkers game in C++ using SDL, a user seeks to determine the location of a jumped-over piece based on the start and end square coordinates. They propose a formula involving the differences in x and y coordinates to find the jumped-over square's position. However, they encounter issues with negative values when jumping upwards. Other participants suggest that the formula should work universally, indicating that the problem may lie in how the coordinates are defined. The conversation highlights the importance of clearly understanding coordinate systems in game development.
Dave2041
Messages
2
Reaction score
0

Homework Statement


in checkers you jump over the enemys piece and land on a square after that.
i'm making this game in c++ using sdl~

i just want to know how to get the square i have jumped over using the end square and start square locations


Homework Equations





The Attempt at a Solution


where sx, sy = start x,y and ex, ey and the end position x,y

disty = ey - sy;
distx = ex - sx;

sx+distx/2 - should be the x val of the square i jumped over

sy+disty/2 - should be the y val of the square i jumped over


is this correct? i tryed it on paper and it seems to work one way but not another, jumping upwards for example gives me a negative number for example, any ideas appreciated :(

should be simple, perhaps i have been looking at this for too long lol.
thanks in advance
 
Physics news on Phys.org
I don't get what you mean by "upwards". Your formula should work regardless. Maybe you failed to give your positions values that mean enough to you, i.e. one corner's square is (0,0) and the opposite corner is (8,8).
 
Last edited:
wow... i just spent a million years thinking that was wrong :'(

thanks anyway!
 
Last edited:
I tried to combine those 2 formulas but it didn't work. I tried using another case where there are 2 red balls and 2 blue balls only so when combining the formula I got ##\frac{(4-1)!}{2!2!}=\frac{3}{2}## which does not make sense. Is there any formula to calculate cyclic permutation of identical objects or I have to do it by listing all the possibilities? Thanks
Since ##px^9+q## is the factor, then ##x^9=\frac{-q}{p}## will be one of the roots. Let ##f(x)=27x^{18}+bx^9+70##, then: $$27\left(\frac{-q}{p}\right)^2+b\left(\frac{-q}{p}\right)+70=0$$ $$b=27 \frac{q}{p}+70 \frac{p}{q}$$ $$b=\frac{27q^2+70p^2}{pq}$$ From this expression, it looks like there is no greatest value of ##b## because increasing the value of ##p## and ##q## will also increase the value of ##b##. How to find the greatest value of ##b##? Thanks
Back
Top