intfiction.org

The Interactive Fiction Community Forum
It is currently Sat May 25, 2013 11:57 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Feb 25, 2012 3:56 pm 
Offline
User avatar

Joined: Fri Jan 27, 2012 2:34 pm
Posts: 271
Location: Boston
The short version:

Are there arrays in TADS 3.1? Or is there a dynamic data structure I can use like an array, to call up a datum by two or more indices?

The long version:

Rant: show
Armed with Ben's Rock-Paper-Scissors code, I now want to create a general NPC-NPC game playing module. This will consult an NPCgame object for the rules.

The advantage to this is that now you can simply define the game rules and add it to the list of games the NPC can play, rather than rewriting the game code many times over. Further down the road this may make it possible to create games where moves can be added in on the fly.

--If it's not clear, I'm using games as a well-defined instance of social interaction. Fuzz out the "win" and "lose" reporting and make a little more narrative the move and countermove, and you have a sort of model for social interaction that doesn't require coding every line by hand. (E.g. _The Games People Play_, by Eric Berne.)

To this end, it would be much simpler if I could just set up a grid in something akin to the normal form game theorists use:

Code:
    R   P   S  <--p1
R   -  p1 p2
P  p2  -  p1
S  p1 p2  -
^
p2


And then call up winResult = gameMatrix[p1move][p2move], or suchlike.


Any way of accessing a datum on two (or more) indices?


Conrad.

_________________
http://tiltedcandle.wordpress.com


Top
 Profile Send private message  
 
PostPosted: Sat Feb 25, 2012 4:19 pm 
Offline

Joined: Sun Mar 01, 2009 8:02 pm
Posts: 902
Possibly making a list of lists?


Top
 Profile Send private message  
 
PostPosted: Sat Feb 25, 2012 5:57 pm 
Offline
User avatar

Joined: Fri Jan 27, 2012 2:34 pm
Posts: 271
Location: Boston
I guess that would be a tree, right?

NPCgameObject.player1moveNode.player2moveNode... I seem to recall doing something like that for a different application some time ago. Probably could do it again.

Thanks, Jim.


Conrad.

_________________
http://tiltedcandle.wordpress.com


Top
 Profile Send private message  
 
PostPosted: Sat Feb 25, 2012 6:03 pm 
Offline
User avatar

Joined: Tue Apr 20, 2010 2:48 pm
Posts: 689
TADS provides three types for this: ByteArray, Vector and List. ByteArray is a basic datatype, Vector and List are classes. You can find information about them in the system manual. Pick your poison:

http://tads.org/t3doc/doc/sysman/toc.htm

Like Jim mentioned, they work similarly to C-like languages. To get a 2D array, you do an array of arrays (or vector/list of vectors/lists).

Edit:
Correction to the above: ByteArray is also a class, not a basic type.


Top
 Profile Send private message  
 
PostPosted: Sat Feb 25, 2012 6:41 pm 
Offline
User avatar

Joined: Fri Jan 27, 2012 2:34 pm
Posts: 271
Location: Boston
Well, ByteArray is worrisome in that it only stores bytes. In the Lists v. Vectors lineup, it seems Vectors would allow the code to tinker with the data more easily.

So I guess Vectors it is!

Thanks, RealNC & Jim.


Conrad.

_________________
http://tiltedcandle.wordpress.com


Top
 Profile Send private message  
 
PostPosted: Sun Mar 04, 2012 3:19 pm 
Offline
User avatar

Joined: Fri Jan 27, 2012 2:34 pm
Posts: 271
Location: Boston
Alright... I've been trying to figure this out for a while, kind of like the Mutual of Omaha footage with a lion trying to figure out a porcupine.

Currently, I'm considering setting this up as a LookupTable. They're designed for stowing away data on a key, which is what I'm doing.

The catch is that I need to stow data away based on TWO keys. Now rather than create an index table of index tables, as I had thought to do with lists / vectors, I'm considering creating an index table of a special object that takes two parameters (=two keys), and indexing on that. Each parameter would be an enumerated, er, thingy. (Symbol? Token?)

The other way to use a two-key system would be to concatenate two strings together. For example, I could create a function that would smash together two player's moves like this:

Code:
smashTogetherTwoPlayersMoves (p1move, p2move)  // both beings strings
   {
        return (p1move + '-vs-' + p2move);
   }
;


Thus the lookupTable would operate on strings like 'ROCK-vs-PAPER'.

I can't help but notice that the lookupTable key examples in the docs all seem to be strings. I expect lookupTables can key on objects of any kind, but I just want something simple and easily doable.

Any thoughts on which approach will be simplest and easiest, for extension into as-yet-unthought-of game move keys?


Conrad.

_________________
http://tiltedcandle.wordpress.com


Top
 Profile Send private message  
 
PostPosted: Sun Mar 04, 2012 4:08 pm 
Offline
User avatar

Joined: Fri Jan 27, 2012 2:34 pm
Posts: 271
Location: Boston
...is there a data class that functions like a set in TADS? Like a list, but without ordering? Or like enum, but with grouping?

C.

_________________
http://tiltedcandle.wordpress.com


Top
 Profile Send private message  
 
PostPosted: Sun Mar 04, 2012 4:36 pm 
Offline

Joined: Tue Apr 27, 2010 1:02 pm
Posts: 797
Why don't you use a two element list as the index value? The ordering is actually useful since the expected result from (Rock, Paper) is not the same as (Paper, Rock).


Top
 Profile Send private message  
 
PostPosted: Sun Mar 04, 2012 6:05 pm 
Offline
User avatar

Joined: Fri Jan 27, 2012 2:34 pm
Posts: 271
Location: Boston
Yeah, but how do I assign content to a filled-out two-item list?

--Or do you mean, use a two-item list as the key?


C.

_________________
http://tiltedcandle.wordpress.com


Top
 Profile Send private message  
 
PostPosted: Sun Mar 04, 2012 8:18 pm 
Offline

Joined: Tue Apr 27, 2010 1:02 pm
Posts: 797
Yes, use a two-item list as a key.

Code:
enum ROCK, PAPER, SCISSORS;
enum WIN, LOSE, DRAW;

modify WaitAction
   execAction() {
      local tab = new LookupTable();

      tab[(ROCK,PAPER)] = LOSE;
      tab[(ROCK,SCISSORS)] = WIN;
      tab[(ROCK,ROCK)] = DRAW;

      if (tab[(ROCK,PAPER)] == LOSE)
         "PAPER beats ROCK. ";
      if (tab[(ROCK,SCISSORS)] == WIN)
         "ROCK beats SCISSORS. ";
      if (tab[(ROCK,ROCK)] == DRAW)
         "ROCK and ROCK is a draw. ";
   }
;


You might also want to have the table's result be a two-item list, so that for example the result for player 1 is at position 1, and the result for player 2 is at position 2.

Code:
tab[(ROCK,PAPER)] = (LOSE, WIN);


This would allow you to mix up the output - you could print "Player 1 wins!" as often as "Player 2 loses!", without having to negate the result from the table.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group