Reading A Command From A Table

I’m still holding out some hope that someone will tell me how my complex skill-check card system can be done, but right now I’m building features blindly and hoping I don’t end up making some critical errors in the foundation that render all the work useless. And I think I may have made a critical error in the foundation that will render all the work useless.

I have a table of cards and a table of the player’s hand. When the hand is redrawn, the table of cards is ordered randomly, a certain number of the rows in the player’s hand are copied from the table of cards, and the rest are blanked out. So far, so good. I think. I can’t find a way to print out the complete contents of the tables which makes it hard to test for, but the code compiles, at least. Here’s the thing: The player then needs to be able to select a card from their hand. I can’t figure out a way to get Inform 7 to wait for a command from the player that matches a specific column of a table the way it can wait for a command that matches a specific value.

I think Hanon said something like this in another hand, but it seems to me as though your life will be a lot easier if you make the cards values or objects with certain properties rather than storing everything in a table. It’ll always be a lot easier to do things through the parser instead of “after reading a command,” and you can refer to properties of the things.

Example 318 in the Inform documentation, “Tilt 1,” does basically exactly what you want. I’m a bit embarrassed to say that I only realized this after I tried another implementation of cards, went looking through the documentation to figure out how to take care of that pesky “of” in the card names, and found this example. So here’s what I’d come up with, with the code for removing “of” borrowed from “Tilt 1”:

A card is a kind of thing.

Suit is a kind of value. The suits are hearts, spades, clubs, and diamonds.

A card has a suit. A card has a number called rank.

The printed name of a card is usually "[Rank of the item described as a rank] of [Suit of the item described]".

Redundancy relates a suit (called X) to a suit (called Y) when X is Y. 

Understand the suit property as describing a card. Understand the rank property as describing a card. Understand "Ace" as 1. Understand "Jack" as 11. Understand "Queen" as 12. Understand "King" as 13. 

After reading a command: 
	 if the player's command includes "of [suit]": 
		while the player's command includes "of": 
 			cut the matched text

To say (spots - number) as a rank:
	if spots is:
		-- 1: say "Ace";
		-- 11: say "Jack";
		-- 12: say "Queen";
		-- 13: say "King";
		-- otherwise: say "[spots in words]".
Casino is a room.

Identity relates a card (called X) to a card (called Y) when the rank of X is the rank of Y and the suit of X is the suit of Y. The verb to be identical to means the identity relation.

There are five cards.

To draw a card:
	if a card (called new card) is off-stage:
		now the suit of new card is a random suit;
		now the rank of new card is a random number between 1 and 13;
		while new card is identical to an on-stage card:
			now the suit of new card is a random suit;
			now the rank of new card is a random number between 1 and 13;
		now the player has new card;
		say "Your hand is full."
When play begins:
	repeat with card running from 1 to 5:
		draw a card.

My solution is a lot less table-reliant than Tilt 1, but Tilt 1 really seems like it’d fit a lot better with what you have so far!

1 Like