Home AMX User Forum NetLinx Studio

Chess Board buttons

Hey,

Been programming some games lately to try and get the brain working again. Come across a problem that I'm having trouble with. Not urgent in any way at all, but your help would be appreciated :)

I've got a chess board on my TP, when a user pressed a square on the board I want to take the GET_LAST of this press, turn them into x & y coordinates and use them to do things in the squares in the horizontal row, vertical row and diagonal row (queens move possibilities). At the moment my buttons are in a 2D array, but I can't use that in a devchan.

The only way I can think of is to have the button array as single dimensional, and based on the GET_LAST of that array, it looks at an array which is 2D ([56][2]) with every coordinate in it. Which just seems lame.

Ideas?

Comments

  • rfletcherrfletcher Posts: 217
    jcerecke wrote: »
    Hey,

    Been programming some games lately to try and get the brain working again. Come across a problem that I'm having trouble with. Not urgent in any way at all, but your help would be appreciated :)

    I've got a chess board on my TP, when a user pressed a square on the board I want to take the GET_LAST of this press, turn them into x & y coordinates and use them to do things in the squares in the horizontal row, vertical row and diagonal row (queens move possibilities). At the moment my buttons are in a 2D array, but I can't use that in a devchan.

    The only way I can think of is to have the button array as single dimensional, and based on the GET_LAST of that array, it looks at an array which is 2D ([56][2]) with every coordinate in it. Which just seems lame.

    Ideas?

    Why can't you use a 2D devchan array?
  • Another option is to use the channel numbers to identify what square was pressed. Since a chess board is an 8 x 8 square, you could label the top left corner as channel number 11, the top right corner is 18, the bottom left corner is 81, and the bottom right corner is 88. Then in your button event, just do button.input.channel / 10 to get the row and button.input.channel % 10 to get the column. Then for horizontal moves, you can just change the column number to what ever it should be while leaving the row the same. For vertical moves, change the row and leave the column alone. For diagonal moves, change both the same amount. To get the new channel number, just multiply the row by 10 and add the column number.

    Hope that helps.
  • mpullinmpullin Posts: 949
    I like Andrew G Welker's suggestion.

    Alternatively, if the channels must be sequential (a1 = 1, b1 = 2, ..., h1 = 8, a2 = 9, etc.) you can use arithmetic as follows:

    nRank = ((BUTTON.INPUT.CHANNEL - 1) / 8) + 1;
    nFile = ((BUTTON.INPUT.CHANNEL - 1) % 8) + 1;
  • PhreaKPhreaK Posts: 966
    The optimum button mapping is going to depend on the board representation you use for any of the AI (even if that's just for possible move highlighting, rather than a computer player).

    One way to approach it might be to set up a dedicated port for your board then assign each button a channel that matches in nicely with array location of the board representation (0x88 might play nicely on the NetLinx box's). The button.input.channel of your data event will then have the array key you need for move calculation.

    If you're not wanting to do any movement animations you could also get funky and set all your buttons up as multi-state where the images assigned to each state line up with your piece value constants.

    Sounds like an awesome little project, keen to see how it turns out.
  • jcereckejcerecke Posts: 40
    Thanks for all the tips! I went with the / and % 10 option. Not sure why... probably just the easiest to understand haha. Now I just need to wait for our next project so I can test it out. AMX should make an netlinx master with lan port and nothing else for testing & small projects like this.
  • shr00m-dewshr00m-dew Posts: 394
    jcerecke wrote: »
    AMX should make an netlinx master with lan port and nothing else for testing & small projects like this.

    They pretty much do with the ME260, but it's a hell of a lot cheaper with a NI700/900. Hell, I picked up a NI900 for my car on ebay for $120.

    Kevin D.
Sign In or Register to comment.