Path with integers
[1/8] from: giovanni::cardona::com at: 7-Dec-2000 14:28
REBOL [ Title: "Path tests for a card game"
Author: "[Giovanni--Cardona--com]"
Comments: {
As a programmer i know this is not
a pretty way to accomplish this, but
i was toying around with the path
possibilities of rebol, and i wonder
if using integers as path is possible
in rebol. Im just starting using Rebol
and I think it rocks!
}
]
;The deck have 40 cards. An individual image path will be added later
cards: [
1 [
type gold
value 11
num 1
]
2 [
type gold
value 0
num 2
]
3 [
type gold
value 10
num 3
]
4 [
type gold
value 0
num 4
]
5 [
type gold
value 0
num 5
]
6 [
type gold
value 0
num 6
]
7 [
type gold
value 0
num 7
]
8 [
type gold
value 2
num 10
]
9 [
type gold
value 3
num 11
]
10[
type gold
value 4
num 12
]
11[
type cups
value 11
num 1
]
]
print cards/10/type ; This prints OK
print cards/11/type ; Integer in path detected!
print cards/9/type
[2/8] from: mdb:gci at: 7-Dec-2000 10:44
Giovanni,
You're having the problem because
cards/1 is 1
cards/2 is [type gold value 11 num 1]
cards/3 is 2
cards/4 is [type gold value 0 num 2]
...
so that cards/1/type results in the error
but cards/2/type works.
Hope this helps
Mike.
[3/8] from: al:bri:xtra at: 8-Dec-2000 15:21
Giovanni, note the following:
>> b: ["one" "two" "three" "four"]
== ["one" "two" "three" "four"]
>> pick b 3
== "three"
>> b/3
== "three"
>> third b
== "three"
Basically, the "/3" is the same as a 'pick, which is the same as 'third.
This is done to make it clear and simple, that the N-th item in a block can
always be retrieved.
Your cards are probably better written as:
Cards: [
Gold 11 1
Gold 0 2
; and so on.
and then use a 'foreach to create a object for each, like:
Deck: make block! divide length? Cards 3
foreach [Type Value Number] Cards [
insert tail Deck make object! reduce [
'Type: Type
'Value: Value
'Number: Number
]
]
That way your Cards are easily changed, stored and retrieved from
storage.
I hope that helps!
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/
[4/8] from: allenk:powerup:au at: 8-Dec-2000 20:09
Hi Giovanni,
If you decompress the cards.bin that I use for all my card games you will
see it is the following format. You don't need to use num within the block
because you can use the card's index position to access them.
card: make object! [rank: 0 suit: none image: none]
cards: reduce [
make card [
rank: 1
suit: 'Clubs
image: load to-binary decompress 64#{....}
]
.....etc...etc ....
make card [
rank: 13
suit: 'Spades
image: load to-binary decompress 64#{....}
]
]
If you could work with the same format, then people can choose to use
whatever card pack they choose. I'd really like to get a set with Cups and
Swords etc.
cards/1/rank
==1
cards/52/rank
==13
In my system, the cards block is a look up table, Card objects aren't stored
anywhere else. All piles in the layout maintain a contents list with the
index numbers of the cards they contain. Saves a lot of memory. If you would
like to use my card game engine, let me know and I'll give you intructions,
it only needs a rule object to be created, and voila you have a new card
game complete with drag & drop, destination testing and scoring. Penguin,
Castle and Roman all use this engine.
Cheers,
Allen K
[5/8] from: giovanni:cardona at: 8-Dec-2000 8:49
Wow Andrew, Thanks for your help! :)
[6/8] from: giovanni:cardona at: 8-Dec-2000 8:50
Thanks for your help Michael,
Im trying to figuring out why. :)
[7/8] from: riachtchenko:docutec at: 12-Dec-2000 12:25
Hi folks,
i wonder if it worked for you,
since i became:
>> foreach [Type Value Number] Cards [
[ insert tail Deck make object! reduce [
[ 'Type: Type
[ 'Value: Value
[ 'Number: Number
[ ]
[ ]
** Syntax Error: Invalid word -- 'Type:.
** Where: (line 3) 'Type: Type
?
Sascha.
Andrew Martin wrote:
[8/8] from: al:bri:xtra at: 13-Dec-2000 6:37
Sascha wrote:
> i wonder if it worked for you,
I didn't try it out, that's why it's got errors. Eventually we (Gabriele and
I) came up with:
[
Rebol []
Cards: [
[Type Value Number]
Gold 0 2
Gold 11 1
Cups 2 4
]
Make-Objects: function [
Table [block!]
Prototype! [object!]
][
Specification Result Object
][
Specification: first Table
Result: make block! to-integer divide length? next Table length?
Specification
foreach :Specification next Table compose/deep [
Object: make Prototype! []
set bind [(Specification)] in Object 'self reduce [(Specification)]
insert tail Result Object
]
Result
]
Prototype: make object! [
f: function [test] [block] [
block: [] ; Don't do this at home!
append block test
probe block
]
Type: lit-word!
Value: integer!
Number: integer!
]
probe Deck: Make-Objects Cards Prototype
halt
]
Which is a generic solution to the problem. Reversing the problem is left as
an exercise for the reader. ;-)
Andrew Martin
ICQ: 26227169 http://members.nbci.com/AndrewMartin/