How to read and print positions

dont have code yet

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

39 Replies - 1961 Views - Last Post: 10 April 2010 - 01:25 AM Rate Topic: -----

#1 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

How to read and print positions

Posted 08 April 2010 - 09:40 PM

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.

Is This A Good Question/Topic? 0
  • +

Replies To: How to read and print positions

#2 bodom658  Icon User is offline

  • Villiage Idiom
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,123
  • Joined: 22-February 08

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?
Was This Post Helpful? 1
  • +
  • -

#3 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

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.
Was This Post Helpful? 0
  • +
  • -

#4 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

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
Was This Post Helpful? 1
  • +
  • -

#5 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

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
Was This Post Helpful? 0
  • +
  • -

#6 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

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:
  • 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.
Was This Post Helpful? 1
  • +
  • -

#7 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: How to read and print positions

Posted 09 April 2010 - 01:11 AM

So where do I begin?
Was This Post Helpful? 0
  • +
  • -

#8 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

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

This post has been edited by gregoryH: 09 April 2010 - 01:16 AM

Was This Post Helpful? 1
  • +
  • -

#9 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

Re: How to read and print positions

Posted 09 April 2010 - 01:17 AM

Number 1 would be fine.
Was This Post Helpful? 0
  • +
  • -

#10 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

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?
Was This Post Helpful? 1
  • +
  • -

#11 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

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.
Was This Post Helpful? 0
  • +
  • -

#12 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

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:

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

Was This Post Helpful? 1
  • +
  • -

#13 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: How to read and print positions

Posted 09 April 2010 - 01:46 AM

Is this a suitable pattern for you?
Was This Post Helpful? 1
  • +
  • -

#14 Sparukus  Icon User is offline

  • D.I.C Head

Reputation: -11
  • View blog
  • Posts: 190
  • Joined: 05-April 10

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!)
Was This Post Helpful? 1
  • +
  • -

#15 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

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

This post has been edited by gregoryH: 09 April 2010 - 01:54 AM

Was This Post Helpful? 1
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3