Note: I skipped last week’s post and this should have been posted yesterday.
THINGS I’VE WORKED ON/COMPLETED…
I have been working on Knights Travails.
ISSUES I HAD…
I didn’t know where to start initially, but I ended up creating a Chessboard object, a Knight object (to represent the current stats of the knight - current position and possible moves) and a getPossibleMoves method which calculated all Possible moves from the current position.
As I was experimenting, I realised that I did not have my game state and game control separated and so I tried to fix that. I had to do a bit of reading to try to get the structure in my head. I have encountered this structure earlier in the course, but could not remember how to structure things and obviously had less knowledge when I first encountered it. It took me a little bit of time to set this up, but it was worth it.
I got as far as pushing the initial moves into an array and then pushing possible moves from the previous moves into the array, but did not know how to track things or tie them together, so asked for some guidance. It’s just as well I did, because I don’t think I would have come up with the right approach alone - not in a reasonable timeframe at least - the idea of noting the ‘parent’ (where a move was generated from) and then marking the square as visited plus the appropriate data structure to house this information.
I realised I need some kind of loop in my runGame function to run until some condition (reaching the final square, for example) was met, but when I first implemented this, I completely missed the point of having a ‘visited’ property on the board and I ended up with an infinite loop due to continually enqueuing squares which had already been visited. I later I fixed this.
THINGS THAT WENT WELL…
When I was trying to figure out all the possible moves from a specific square, relative to x and y co-ordinates, I realised that rather than manually work them out myself, I could use AI to help me. Note I do not use AI to write code at all, but I actually found it very useful for these types of tasks.
THINGS I’VE LEARNT/NEED TO IMPROVE ON…
n/a
OTHER…
n/a
PLAN FOR THE UPCOMING WEEK…
Continue with Knights Travails.
Top comments (0)