AltME: Rebol School

Messages

Maxim
almost done, but I've got an errand to do, will be back with the solution in about 1h30
Reichart
:)
Maxim
I had a LOT of fun building this... its not perfect (backspace and delete cannot function in this mode cause I am not storing the console's screen buffer, but it goes a long way with just 40 lines... the vast majority of the code is actually managing the console's low level port interface.
rebol []
either attempt [lcl-port: open/lines tcp://:33101] [
    rmt-port: 33102
][
    lcl-port: open/lines tcp://:33102
    rmt-port: 33101
]
con: open/binary [scheme: 'console]
remote-port: none
digit: charset "0123456789"
forever [
    p: wait [lcl-port con]
    either p == con [
        key: first con
        either key = 27 [
            read-io con io: head clear "" 3
            cmd: copy "K [27 "
            foreach c io [ append cmd to-integer c append cmd " "]
            append cmd "]^/"
            chars: join "^[" io
        ][
            cmd: rejoin [ "K " key "^/" ]
            chars: to-char key
        ]
        
        insert ( rp: open rejoin [tcp://localhost: rmt-port] ) cmd
        close rp
    ][
        cmd: first first lcl-port
        parse cmd [
            "K " here:
            "[" (chars: to-string to-binary load here)
            
            | ( chars: to-char load here )
        ]
    ]
    prin chars
]
basically, store the script and run it twice,  both consoles are linked as if you where typing in anyone of them.  type in any of the two, and the other types the same thing!
we could modify the script a little to make it work across two different machines.  in that case, instead of changing the port number, we'd change the remote ip address instead.
DocKimbel
Instead of:
    insert ( rp: open rejoin [tcp://localhost: rmt-port] ) cmd
    close rp
you could use simply:
    write rejoin [tcp://localhost: rmt-port] cmd
Gregg
That's very cool Max.
Reichart, you just asked for smallest and simplest. :-)
Maxim
doc, yeah, true, I forgot we could use write on tcp ports.
for those who did not try the above script... do it (in 2.7.8) its pretty fun.
Reichart
"we could modify the script a little to make it work across two different machines.
That is the KEY, add that :)

Gabriele
Arnold
Johnk replied pointing to so chat, where my answer is too. Not going to subscribe to yet another site, there's too many already.
I have another nice question. I have 6 integers from 0 to about 23000 and I like to hash these. I calculated the 6 integer would fit into 96 (3 x 32 bit) bits. Any FUN ideas on howto do this?
Gregg
What is the context and the goal?

Arnold
The context is creating a Chinese chess game. I divided the board into 6 equal pieces and use the fieldcode and piece to calculate a number, I took some precautions that should make it unique. For the startposition the values are hash-1: 1508 hash-2: 2232 hash-3: 1508 hash-4: 1802 hash-5: 2293 hash-6: 1802, When I calculate for a maximally filled area there is an upperbound of approximately 23000. But I think in practice it could always be under 8000.
I could have gone the easy path and copy existing C programs using the bitboards and corresponding Zobrist hashing functions. But the easy path is boring and leads nowhere too ;-) So I decided to play around & find out an alternative way.
Arnold
I will have to shuffle my multiplication factors a bit more for now a black king of value 129 can be placed on a field with factor 115 giving 14835, that is a bit too much of a good thing :-)
Arnold
Placed a file in Rebol-school folder. You can see the board with pieces and a multiplication table that is the original field number multiplied with prime factor 3, 5, 7 and 11 for columns 2, 3,4 and 5. After that it is mirrored and reshuffled a bit to the other 5 sixths.
Maxim
Reichart, revised script with setup for two hosts.  all you need to setup the host names. if machines are on the same intranet, just their local host name should be ok.
rebol []
;-------
; note:  app must be launched on hosts in the order they are given here (this is a quick demo)
;
; replace foo & bar with hosts, or use localhost in both to launch both on a single host.
;-------
host-A: tcp://foo:33101
host-B: tcp://bar:33102
spec-A: net-utils/url-parser/parse-url ( context [url: host-A  host: port-id: none  serv-url: does[rejoin [tcp://: port-id ]]] ) host-A
spec-B: net-utils/url-parser/parse-url ( make spec-A [url: host-B] ) host-B
; try to connect to first host as client... if not available, then we are first host
either (attempt [ rmt-port: open host-A  close rmt-port true ])[
    lcl-spec: spec-B
    rmt-spec: spec-A
][
    lcl-spec: spec-A
    rmt-spec: spec-B
]
    
lcl-port: open/lines lcl-spec/serv-url
rmt-port: rmt-spec/url
print rejoin ["'" lcl-spec/host "' serving shared terminal on port: " lcl-spec/port-id]
con: open/binary [scheme: 'console]
remote-port: none
digit: charset "0123456789"
forever [
    p: wait [lcl-port con]
    chars: ""
    either p == con [
        key: first con
        either key = 27 [
            read-io con io: head clear "" 3
            cmd: copy "K [27 "
            foreach c io [ append cmd to-integer c append cmd " "]
            append cmd "]^/"
            chars: join "^[" io
        ][
            cmd: rejoin [ "K " key "^/" ]
            chars: to-char key
        ]
        
        insert ( rp: open rmt-port ) cmd
        close rp
    ][
        conn: first lcl-port
        if  (cmd: pick conn 1) [
            parse cmd [
                "K " here:
                "[" (chars: to-string to-binary load here)
                
                | ( chars: to-char load here )
            ]
        ]
    ]
    prin chars
]
Reichart
....that is very nice.  I will set up a second computer soon to play with this.
Next step, get them talking outside the net.    
The reason this "seed" of code is important, is once people see how truly easy this is, there are hundreds of cool little tools that use this as a base.
Gregg
It looks like they should already talk to any machine Reichart. Just config the names in Host-A/B.

Last message posted 184 weeks ago.