lol programman

  • Join the GBAtemp community: it's free
    • 50% fewer ads
    • Reply alerts
    • Join the discussion
    • Watch & bookmark
Status
Not open for further replies.

BeatriceTheGolde

Banned!
Banned
Joined
Apr 10, 2009
Messages
60
Reaction score
0
Trophies
1
Website
tempchan.co.cc
XP
60
Country
Canada
I was in a programming competition today.

Three hours.

Five problem sets.

I got the first three, super easy.

I probably could've figured out the fourth one, but I guess I spent too much time trying at the fifth one.

Like, holy shit.

PROBLEM:
Chessboard.
Two points.
Find how many moves it would take for a knight to get from one to the other.
Note: Knight cannot leave the 8 x 8 board.

After piles of nested for loops and if statements, I gave up because shit was too hard.
 
doesnt that question require knowledge of how chess works?
 
From one edge to the other, without the other pieces in the way ?
(The knight is the horse ? maybe I mixing)
wouldn't it be 4, step 2 by 2 in Y (whatever the x is, making sure X is not 8)
if you start moving in Y first to move the more to the other edge, X should not go out. if you make X one time positive and one time negative.

x=1;
for (y=1, y
 
Advice Dog said:
What's the problem again? WHich points exactly? Or is it like a knight's tour around the entire board?
Find the shortest number of moves for a knight to move from one point to another. The two points are variables.

Joe88 said:
doesnt that question require knowledge of how chess works?
No, just how a knight moves.

QUOTE(Cyan @ Feb 23 2010, 05:19 PM)
From one edge to the other, without the other pieces in the way ?
wouldn't it be 4, step 2 by 2 in Y (whatever the x is, making sure X is not 8)
if you start moving in Y first to move the more to the other edge, X should not go out. if you make X one time positive and one time negative.
Knights can't have anything in their way, they jump. They have eight possible moves:
x + 2, y + 3
x + 2, y - 3
x + 3, y + 2
x + 3, y - 2
x - 2, y + 3
x - 2, y - 3
x - 3, y + 2
x - 3, y - 2

Possible x values: 0-7 OR 1-8.
Possibly y values: 0-7 OR 1-8.
 
BeatriceTheGolden said:
Find the shortest number of moves for a knight to move from one point to another. The two points are variables.
Oh, ok.

QUOTE(BeatriceTheGolden @ Feb 23 2010, 11:24 PM) They have eight possible moves:
x + 2, y + 3
etc.
x+2 y+3 ?
isn't x+2, y+1 ?
 
Cyan said:
BeatriceTheGolden said:
Find the shortest number of moves for a knight to move from one point to another. The two points are variables.
Oh, ok.

QUOTE(BeatriceTheGolden @ Feb 23 2010, 11:24 PM) They have eight possible moves:
x + 2, y + 3
etc.
x+2 y+3 ?
isn't x+2, y+1 ?
Nope, it's 2 and 3.
L-shaped.
 
yes, count the number of squares from the knight to where it can move, I count +2+1, +2-1, -2-1, -2+1, +1-2, +1+2, -1+2, -1-2 :
http://en.wikipedia.org/wiki/Knight_%28chess%29

You are making a big jump with +3+2 instead of +2+1
maybe you think about "3squares,2squares" in total between 2 spots, instead of "+2 square, +1square from current position" ? in that I agree

I think it's easier to calculate the number of square you really need to move, instead of the position-position jump. (maybe it can be done too, I'm just thinking that way first)
 
Cyan said:
yes, count the number of squares from the knight to where it can move, I count +2+1, +2-1, -2-1, -2+1, +1-2, +1+2, -1+2, -1-2 :
http://en.wikipedia.org/wiki/Knight_%28chess%29

You are making a big jump with +3+2 instead of +2+1
maybe you think about "3squares,2squares" in total between 2 spots, instead of "+2 square, +1square from current position" ? in that I agree

I think it's easier to calculate the number of square you really need to move, instead of the position-position jump. (maybe it can be done too, I'm just thinking that way first)
...shit.
 
I'm thinking about a theory :

1)
Check which is higher (X or Y) from point A to point B, and set it to 2, the lower to 1

ex.
Point A : 4,8
Point B : 3,5
X : 4 to 3 is shorter than 8 to 5, so preferred direction is Y for 2 square, and X for 1 square.


2)
Detect if (Abigger-1 > Bsame) (if Ax-1 > Bx)
If bigger go near
If shorter, move away

(Don't know if it can be done if points are too near though)

3)
My theory is too fresh, I have to check it more, sorry XD

(Sorry, very messy bellow, don't take it for good, I edited it many times)

but if I follow 1 and 2 :
Starting point A : 4,8
check if x or y is greater :
if ((biggerX-shorterX) < (biggerY-shorterY)) then Y is +/-2, x is +/-1 (else, the contrary)

check if Y is + or - :
if (TargetY < knightY) Y is minus, else is plus

check if x is + or - :
if (biggerX-1 > smallerX) then go near (to go near : if targetX < knightX, X is minus)
Ax-1 == Bx then go away
target point1 : 5,6

from A5,6 to B3,5 now :
X 5-3 =2
Y 6-5 = 1
set +/- 1 to Y, and -2 to X

choose + or - to Y :
if biggerY-1 < smallerY then go away, else got near
biggerY-1 : A6-1 == By : go near : Y is negative

X-2y-1 : target found in 2 moves.

Edit : in fact, it could need to check 1 move ahead to decide which direction to go.
I quit for today, I'm going to bed
tongue.gif


I'll be glad to read the way to do it (or the final code) if someone makes it. thanks ^^
 
Status
Not open for further replies.

Site & Scene News

New Hot Discussed User Submitted