• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

need help in hashtabele

Status
Not open for further replies.
Level 2
Joined
Feb 2, 2012
Messages
11
i am making a chess map at the moment.
i would like to make a hastabele and set values like these

chessgird:
8a 8b 8c 8d 8e 8f 8g 8h
7a 7b 7c 7d 7e 7f 7g 7h
6a 6b 6c 6d 6e 6f 6g 6h
5a 5b 5c 5d 5e 5f 5g 5h
4a 4b 4c 4d 4e 4f 4g 4h
3a 3b 3c 3d 3e 3f 3g 3h
2a 2b 2c 2d 2e 2f 2g 2h
1a 1b 1c 1d 1e 1f 1g 1h

my gird
((8x)(1y)) ((8x)(2y)) ((8x)(3y)) ((8x)(4y)) ((8x)(5y)) ((8x)(6y)) ((8x)(7y)) ((8x)(8y))
((7x)(1y)) ((7x)(2y)) ((7x)(3y)) ((7x)(4y)) ((7x)(5y)) ((7x)(6y)) ((7x)(7y)) ((7x)(8y))
((6x)(1y)) ((6x)(2y)) ((6x)(3y)) ((6x)(4y)) ((6x)(5y)) ((6x)(6y)) ((6x)(7y)) ((6x)(8y))
((5x)(1y)) ((5x)(2y)) ((5x)(3y)) ((5x)(4y)) ((5x)(5y)) ((5x)(6y)) ((5x)(7y)) ((5x)(8y))
((4x)(1y)) ((4x)(2y)) ((4x)(3y)) ((4x)(4y)) ((4x)(5y)) ((4x)(6y)) ((4x)(7y)) ((4x)(8y))
((3x)(1y)) ((3x)(2y)) ((3x)(3y)) ((3x)(4y)) ((3x)(5y)) ((3x)(6y)) ((3x)(7y)) ((3x)(8y))
((2x)(1y)) ((2x)(2y)) ((2x)(3y)) ((2x)(4y)) ((2x)(5y)) ((2x)(6y)) ((2x)(7y)) ((2x)(8y))
((1x)(1y)) ((1x)(2y)) ((1x)(3y)) ((1x)(4y)) ((1x)(5y)) ((1x)(6y)) ((1x)(7y)) ((1x)(8y))


white pawn (+1x)
black pawn (-1x)
knight (+1x +2y) (+1x -2y) (-1x +2y) (-1x -2y) (+2x+1y) (+2x -1y) (-2x+1y) (-2x -1y)
bishop (+ax +ay)
rook (+ay) (+ax)
queen (+ax +ay) (+ay) (+ax)
king (-1x) (-1x -1y) (-1y) (-1y +1x) (+1x) (+1x +1y) (+1y) (-1x +1y)


sience there is no way to use letters like x and y i wuold like to know how i can do it by an other way

greetings
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
You can hash strings, no problem. There's the StringHash() native, or use Hashtable - Get String ID if you're using GUI.

You could give each square an integer id. Using coordinates running from (1,1) to (8,8). Give x coordinate multiplier of 10 to avoid id collisions. Id of (1,1) would be 1*10+1=11. Id of (5,6) would be 5*10+6=56.

When you want to move, you get the current square id and add to movement value to it. If you're in (4,4) and want to move +2x,+1y your new id is 4*10+4+2*10+1=65. Load the correct square with the 65 id.

However without knowing more details about the system I can't say much.
 
Level 2
Joined
Feb 2, 2012
Messages
11
hi maker
thanks for your answer

i made the cordinate system like you said

a1 = 1 of 1
a8 = 8 of 1
h1 = 1 of 8
and h8 =8 of 8

but i really have no idea how to give x coordinate multiplier of 10 :S
and there will be some leaks with the stystem u sugested i think because some figures may jump over lanes.

greetings
 
Level 2
Joined
Feb 2, 2012
Messages
11
hi thatnk you for your answer
the tabele like you sugested it would look like this
Standard chess grid
A1 B1 C1 D1 E1 F1 G1 H1
A2 B2 C2 D2 E2 F2 G2 H2
A3 B3 C3 D3 E3 F3 G3 H3
A4 B4 C4 D4 E4 F4 G4 H4
A5 B5 C5 D5 E5 F5 G5 H5
A6 B6 C6 D6 E6 F6 G6 H6
A7 B7 C7 D7 E7 F7 G7 H7
A8 B8 C8 D8 E8 F8 G8 H8

Hashtable Data grid
10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33
34 35 36 37 38 39 40 41
42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57
58 59 60 61 62 63 64 65
66 67 68 69 70 71 72 73

lets take a look on knights moves: -15,-6,+10,+17,+15,+6,-10,-17
when thr knight is on field 45 this trigger would be correct, but when he is on a firld like 42 and have to move +6 he will move 7 squares in a row. that is why i think a x and y value would be better.

i plan to move units like that:
when player selects a unit and its his turn. there will spawn (white) circles of power at the place where this figure can move to. when he unselects it they will disapear. at the place where he can beat an other figure of the enemy should spawn an (red) circle of power. when the player will leftklick or select one of this circles the unit will move there.

hope you have any idea :D

greetings
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Damn! This looks so interesting...

I think you should "square" the numbers.

01 02 03 04 05 06 07
11 12 13 14 15 16 17
21 22 23 24 25 26 27.
31 32 33 34 35 36 37
41 42 43 44 45 46 47
51 52 53 54 55 56 57
61 62 63 64 65 66 67
71 72 73 74 75 76 77

So you can create the circles on the respective squares just playing with numbers.

Lets say my queen is in square #44. She should be able to move Horizontally (41, 42, 43, 45, 46, 47) vertically (04, 14, 24, 34, 54, 64, 74) and diagonals (11, 22, 33, 55, 66, 77 -- 71, 62, 53, 35, 26, 17). This way you can achieve things by adding 1, 2, 3, 4, 5, 6, 7, or multiplying by 10, or both. You would have to create a pathing formula for each unit, detect where the unit is standing, and which slots are available for that unit.

Using random positions to explain:
Horizontal is 10x1+1, 10x1+2, 10x1+3, etc. to 7
Vertical is 10x1+1, 10x2+1, 10x3+1
Diagonal (to Top Right) is 10x4+1, 10x3+2, 10x2+3, 10x1+4
Diagonal (to Bot Right) is 10x4+1, 10x5+2, 10x6+3, 10x7+4
Diagonal (to Top Left) is 10x7+7, 10x6+6, 10x5+5, 10x4+4.
Diagonal (to Bot Left) is 10x1+7, 10x2+6, 10x3+5, 10x4+4.

After detecting where the unit is (44) you have to look at that number as a 10x4 + 4. Then run a loop to check horizontal path. You have to check in a range from 10x4+1 to 10x4+7 if there's any enemy unit. If there is, know where it's standing (lets say at 41 and 46). Then check the relation between the enemy slot and your unit slot (41 - 44) and (46 - 44). If the number is negative, it means the unit is on your left (41-44 = -3). If the number is positive, it means it's on your right (46-44 = 2). Then you have to create 3 circles to your left and 2 circles to your right. You loop again and create the circles on 41-44, 42-44, 43-44. Then you do the same for your right. Then vertically, then on diagonals.

lol... it's a lot easier writing and reading that doing xD The good thing is that it's mostly a number problem, it's math, and math can be solved. There must be tons of Chess formulas around there.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Most of the previous posts suggested a mapping from the position vectors (x, y) to a single array index (i), like f:(x, y) -> x*10 + y. While this would be a decent solution in combination with a 1 dimensional array, there is really no point in using this with hashtables which are 2 dimensional and therefore can be directly indexed by a 2d vector.

On the other hand a hashtable actually has a different purpose and with 8 x 8 fields you dont need hashing. A cleaner solution would be to use a vJass 2d array or one of the above posted solutions (the (x,y) -> x*10 + y or (x,y) -> x*8 + y looks good) in combination with an array (BUT NOT A HASHTABLE) - which is internally the same.
 
Level 2
Joined
Feb 2, 2012
Messages
11
Hi i would like it to do like Spartipilo sugested
what do i do as next? :S
 

Attachments

  • BIGBOZZ.w3x
    45.4 KB · Views: 36
Status
Not open for further replies.
Top