0

I'm making a chess-like game and, in order to make the various moves, I want to read some user input like "11-12" to move the piece located at the "coordinates" 1-1 to the position 1-2. I want to convert the string "11-12" to a list like [1,1,-,1,2]. I would like to end up with something like this:

...
read(Play),
convert_play_to_list_L(Play, L),
element_at(StartX,L,1),
element_at(StartY,L,2),
element_at(EndX,L,3),
element_at(EndY,L,4),
...

example: Play = "1112" , L = [1,1,1,2] , StartX = 1 , StartY = 1 , EndX = 1 , EndY = 2

false
  • 10,264
  • 13
  • 101
  • 209
136
  • 1,083
  • 1
  • 7
  • 14
  • The most common way to do this is to use regular terms. That is, to type `11-22.` or `"1112".` instead of the same without the dot. – false Nov 09 '19 at 21:45
  • But how do I convert that to a list? – 136 Nov 09 '19 at 21:51
  • See [this](https://stackoverflow.com/a/8269897/772868) for more. That is, it is already a list – false Nov 09 '19 at 21:52
  • I still don't understand how can I turn 'Play' into a list after reading it – 136 Nov 09 '19 at 22:46
  • 1
    It **is already** a list! – false Nov 09 '19 at 23:08
  • Please try to follow the link indicated. With the appropriate flag given there, ihe input `"abc".` is tantamount to `[a,b,c].` – false Nov 09 '19 at 23:23
  • I've got it working. I needed to add the "". Thanks a lot and sorry for being so "slow" :) . Do you know how to convert the ASCII codes into integers? – 136 Nov 09 '19 at 23:40
  • `number_chars/2` – false Nov 09 '19 at 23:45
  • With `set_prolog_flag(double_quotes, chars)`, there are no ASCII-codes involved - as indicated in the answer I linked. – false Nov 09 '19 at 23:48

0 Answers0