-4

I have a class project which was given to me today and is due in 2 weeks. I have to make a knight from a chess board move around (just the knight, no other pieces) and I have started with this:

import math  
print("This is the program for the knight's movement in chess, Press Y when you are ready to move on.") 
input ("Would you like to move on?") 
position=int(input("What position is your knight in?")) 
print("If your knight is in the position",position,"you may move either 2 forward and 1 left, or 2 forward and 1 right, or the other way so 2 backward 1 left, or 2 backward and 1 right.")

...but I don't know how to move on. Does anybody have any advice?

I am only looking for advice not asking for answers so please don't tell me to si on it I was just stuck with one problem and couldn't find a way around it thanks for reading my problem Regards Roscomadrid

  • Perhaps sit on it for more than a day before coming for help. As it stands, you don't even bother to check whether the user said `"Y"` to moving on. – jonrsharpe Mar 04 '14 at 12:11
  • if you feel like this should be voted down please leave a comment as to why it isn't worth being answered! – Roscomadrid Mar 04 '14 at 12:14
  • ok thanks for the advice it's just i feel like it could be a long and perhaps rushed last minute thing unless i get help now but again thanks for the advice and i will do. regards Roscomadrid – Roscomadrid Mar 04 '14 at 12:19
  • Thanks for the heads up I Weill take a better look at it next time and consider all other possible routes thank you Dirk – Roscomadrid Mar 04 '14 at 12:52

1 Answers1

2

Step back from the code for a moment and spend some time thinking about how to actually approach the problem. There are a few separate steps involved in a problem like this:

1) What data structure will you use to represent the chessboard?

If you asked ten people this question you'd probably get ten different answers. Think of a few different possibilities, and select the one you like the most. One simple example might be an 8x8 array, but what advantages and disadvantages does that have? Might there be anything better?

2) How can I represent a move?

Again, many possible choices. You could have a Move class, a (fromSquare, toSquare) tuple, etc. The answer to this question will depend to some extent on your choice of data structure in part one.

3) How can I generate the set of legal knight moves?

Probably the trickiest aspect. You'll need to devise an algorithm that computes every legal (from, to) pair, using whatever move representation you selected. You will have to pay attention to what happens near the edge of the board to ensure that the knight cannot fall off, or wrap around to the opposite side of the board.

Once you have an answer to all of these, sit back down and work your way through the code slowly. Get one thing working at a time; perhaps the first milestone could be a little printout of the current board position?

Good luck with your assignment.

Tetrinity
  • 1,105
  • 8
  • 20
  • Thank you so much this is the advice I was looking for maybe a little criticising but it's agreeable and this type of answer is what I was hopping for in the snense of a step by ATP to win over the "assignment" so again thank you so much Tetrinity regards Roscomadrid – Roscomadrid Mar 04 '14 at 13:00