Hey guys,
So I’m trying out some more challenges but I have no idea where to start.
I have an [8] by [8] character text file each character has a position in the 8x8 grid.
I need to know how I can determine a characters position in the grid then output what can move forward by one square (and print their positions). These characters can only move up or down by one square.
I have no code, I don’t even know where to start I’m very novice at c++ but trying to learn by completing these challenges.
Thanks.
How to read and print positionsdont have code yet
39 Replies - 1551 Views - Last Post: 10 April 2010 - 01:25 AM
Replies To: How to read and print positions
#2
Re: How to read and print positions
Posted 08 April 2010 - 10:22 PM
Are you just trying to move them each one space to the left if they can be?
#3
Re: How to read and print positions
Posted 09 April 2010 - 12:07 AM
no,
Imagine an 8x8 grid:
0:12345678
1:xxxxxxx
2:xxxxxxx
3:xxxxxxx
4:xxxxxxx
5:xxxxxxx
6:xxxxxHx
7:xxxxxXx
8:xxxxxxx
You see the capitle X in the grid how would I be able to tell (and print its position) that it can move forward (to line/row number 6,7(H))
Now imagine for a second that (H) was blocked lets turn (H) into (N) (for No-go) but N could be a variable, so some of the (X)'s could move forward but some couldnt because they were blocked.
I want to be able to only print the positions of the (X)s that can move forward or up the line (I say up but in a numerical sense it would be back 8,7,6 etc) depending on how the grid is read offcourse.
So does any one know how to code such a mind boggler?
Thanks.
Imagine an 8x8 grid:
0:12345678
1:xxxxxxx
2:xxxxxxx
3:xxxxxxx
4:xxxxxxx
5:xxxxxxx
6:xxxxxHx
7:xxxxxXx
8:xxxxxxx
You see the capitle X in the grid how would I be able to tell (and print its position) that it can move forward (to line/row number 6,7(H))
Now imagine for a second that (H) was blocked lets turn (H) into (N) (for No-go) but N could be a variable, so some of the (X)'s could move forward but some couldnt because they were blocked.
I want to be able to only print the positions of the (X)s that can move forward or up the line (I say up but in a numerical sense it would be back 8,7,6 etc) depending on how the grid is read offcourse.
So does any one know how to code such a mind boggler?
Thanks.
#4
Re: How to read and print positions
Posted 09 April 2010 - 12:39 AM
hi sparcus
the problem you have will need the use of integer modulus and divide ( % / ) operators to give you a way to move between rows/columns
the problem you have will need the use of integer modulus and divide ( % / ) operators to give you a way to move between rows/columns
#5
Re: How to read and print positions
Posted 09 April 2010 - 12:47 AM
Could you explain how I would use such a method? Because I dont even know what I am doing, I know it sounds strange altho I can explain it I dont know what it is I am ment to do?
If any one has some sample code of even something slightly similar, something to get my rodent brain to eat. I would appreciate the effort as this is only a lesson for learning.
Thanks
If any one has some sample code of even something slightly similar, something to get my rodent brain to eat. I would appreciate the effort as this is only a lesson for learning.
Thanks
#6
Re: How to read and print positions
Posted 09 April 2010 - 01:00 AM
ok,
analysis is a very important step in these problems. You need to distance yourself from code and analyse the problem
Here is an idea on analisys: GROW principle.
Goal - What is the goal?
Reality - What is the current reality?
Obstacles/Options - What are the obstacles or Options?
Way forward.
Goal
The goal is to be able to moves pieces on a "board" represented by an x * y array using program code.
Reality
The reality is not knowing where to start
Obstacle/Option
obstacle is as above
Options open to you include:
I know that "thinking in patterns" is a great approach to this as you cna easily extend this into any problem you face.
Way Forward
Let me coach you on here and see how we can turn the problem into a pattern that will turn quickly into code.
analysis is a very important step in these problems. You need to distance yourself from code and analyse the problem
Here is an idea on analisys: GROW principle.
Goal - What is the goal?
Reality - What is the current reality?
Obstacles/Options - What are the obstacles or Options?
Way forward.
Goal
The goal is to be able to moves pieces on a "board" represented by an x * y array using program code.
Reality
The reality is not knowing where to start
Obstacle/Option
obstacle is as above
Options open to you include:
- Just get code - learn nothing
- learn "thinking in patterns"
- apply "thinking in pattern" skill to this problem
- Extend thinking in patterns to other problems
I know that "thinking in patterns" is a great approach to this as you cna easily extend this into any problem you face.
Way Forward
Let me coach you on here and see how we can turn the problem into a pattern that will turn quickly into code.
#7
Re: How to read and print positions
Posted 09 April 2010 - 01:11 AM
So where do I begin?
#8
Re: How to read and print positions
Posted 09 April 2010 - 01:15 AM
we can express the positions on the grid in two ways:
1. as a number from 0 to (x * y)-1 in this case, 0 - 63
2. as a pair of co-ordinates 0 and side-1, in this instance 0-7 and 0-7
Feel free to ask a question if you like
1. as a number from 0 to (x * y)-1 in this case, 0 - 63
2. as a pair of co-ordinates 0 and side-1, in this instance 0-7 and 0-7
Feel free to ask a question if you like
This post has been edited by gregoryH: 09 April 2010 - 01:16 AM
#9
Re: How to read and print positions
Posted 09 April 2010 - 01:17 AM
Number 1 would be fine.
#10
Re: How to read and print positions
Posted 09 April 2010 - 01:21 AM
good,
what we want is to develop the idea of moving around that 0-63 squares,
What are the restrictions that apply, for example you can't move to square -1, what other things restrict movement?
what we want is to develop the idea of moving around that 0-63 squares,
What are the restrictions that apply, for example you can't move to square -1, what other things restrict movement?
#11
Re: How to read and print positions
Posted 09 April 2010 - 01:25 AM
Anything negative anything past 63 and obviously decimal places are a no no.
Feel free to add to anything I am missing.
Thanks
O also any variables that I may declare are off squares aswell.
Feel free to add to anything I am missing.
Thanks
O also any variables that I may declare are off squares aswell.
#12
Re: How to read and print positions
Posted 09 April 2010 - 01:28 AM
Cool sparukus,
your on the way to thinking in a pattern. Your have correctly identified the ends as a restriction.
Now I would like to turn your attention to the layout of the grid, I am thinking like this at the moment:
your on the way to thinking in a pattern. Your have correctly identified the ends as a restriction.
Now I would like to turn your attention to the layout of the grid, I am thinking like this at the moment:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ... etc to 63
This post has been edited by gregoryH: 09 April 2010 - 01:33 AM
#13
Re: How to read and print positions
Posted 09 April 2010 - 01:46 AM
Is this a suitable pattern for you?
#14
Re: How to read and print positions
Posted 09 April 2010 - 01:51 AM
Ok I get you...
haha I actualy get it now all I have to do is -8 to be able to find out what square I can move upwards.
Thats amazing how you just made me do that lol
But this doesnt solve the problem of how determine if there is an obstacle in the way?
(btw thanks your a good teacher!)
haha I actualy get it now all I have to do is -8 to be able to find out what square I can move upwards.
Thats amazing how you just made me do that lol
But this doesnt solve the problem of how determine if there is an obstacle in the way?
(btw thanks your a good teacher!)
#15
Re: How to read and print positions
Posted 09 April 2010 - 01:52 AM
yes - now you get it,, and why analysis of a problem is so important.
Part two
Goal - how do I determine if there is something there
part three
Goal - printing the array on the console
Part two
Goal - how do I determine if there is something there
part three
Goal - printing the array on the console
This post has been edited by gregoryH: 09 April 2010 - 01:54 AM
|
|

New Topic/Question
Reply




MultiQuote




|