Friday 27th October 1995 Coding Lecture 4 ---------------- [Academy] Mark_Farrell sits and twiddles his thumbs in the Carlin. Coding lecture/workshop for anyone who is interested :-\ [Academy] Sir_Isaac: <*> On my way... Sir_Isaac has arrived. Sir_Isaac enters from the Quad. Mark_Farrell smiles Sir_Isaac walks down the aisle and takes a seat up front. Sir_Isaac says "That makes, well, one so far. :)" You say "Aye, make yourself at home." Sir_Isaac sets up a fireplace, takes out a compact easy chair, and pulls out a copy of Popular Federation Science. Sir_Isaac says "Guess I took it a little too far. :)" You say "WEll, as it's a 1-to-1, what do you want to talk about as regards coding?" Sir_Isaac says "Actually, tonight's lecture seemed quite interesting. Want to go with that?" You say "Well, tonights lecture was going to continue with the poker table." You say "THe basic intro was covered in lecture 2." Sir_Isaac says "All the better. That's where I left off, lecture two. :)" Saving TrekMUSE DataBase. Response will be slow for a few minutes. Sir_Isaac says "Remember? Me and the Binars?" You say "Right." You say "Lecture 3 covered the basics of shuffling." WiP(#126vI) Work In Progress for Coding Workshop. A poker table. Owner: Mark_Farrell Credits: 1 Status: Thing Org: None(#-1) Type: Thing Flags: visible inherit Ve:$shuffle:new deck;@xb me=[shuffle(get(me/xa),13)];@xc me=[shuffle(de_(first(get(me/xb))),13)];@xd me=[shuffle(de_(first(get(me/xc))),13)];@xe me=[shuffle(de_(first(get(me/xd))),13)];@xf me=[rest(get(me/xb))] [rest(get(me/xc))] [rest(get(me/xd))] [rest(get(me/xe))];@xg me=[edit(get(me/xe),:,spc(1))] Xg:21 19 72 18 39 130 74 133 24 132 43 137 17 66 134 38 41 67 73 20 45 136 27 42 37 135 141 129 77 22 23 34 140 75 35 76 28 29 71 70 36 139 33 65 44 26 138 40 69 68 131 25 Xf:21 19 72 18 39 130 74 133 24 132 43 137 17 66 134 38 41 67 73 20 45 136 27 42 37 135 141:: 129 77 22 23 34 140 75 35 76 28 29 71 70 36 139: 33 65 44 26 138 40 69 68 131 25 Xe:: 70 36 139: 33 65 44 26 138 40 69 68 131 25 Xd:25_26_33_36_40_44_65_68_69_70_131_138_139: 141:: 129 77 22 23 34 140 75 35 76 28 29 71 Xc:22_23_25_26_28_29_33_34_35_36_40_44_65_68_69_70_71_75_76_77_129_131_138_139_140_141:: 66 134 38 41 67 73 20 45 136 27 42 37 135 Xb:20_22_23_25_26_27_28_29_33_34_35_36_37_38_40_41_42_44_45_65_66_67_68_69_70_71_73_75_76_77_129_131_134_135_136_138_139_140_141: 21 19 72 18 39 130 74 133 24 132 43 137 17 Ulock:Mark_Farrell(#16055PDeoqFc) Race:Mechanoid Vc:Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King Joker Va:$test *:@emit > %N types %0. The value returned is 'The [extract(v(vc),band(v(0),15),1)] of [lookin(v(vb),band(v(0),240),1)]'. Vb:16 Clubs 32 Diamonds 64 Hearts 128 Spades Lock:Mark_Farrell(#16055PDeoqFc) Xa:17 18 19 20 21 22 23 24 25 26 27 28 29 33 34 35 36 37 38 39 40 41 42 43 44 45 65 66 67 68 69 70 71 72 73 74 75 76 77 129 130 131 132 133 134 135 136 137 138 139 140 141 Vd:$new deck:@xa me=[iter2(lnum(13),{[add(##,16)]})] [iter2(lnum(13),{[add(##,32)]})] [iter2(lnum(13),{[add(##,64)]})] [iter2(lnum(13),{[add(##,128)]})] Home: Ready Room Location: Carlin Auditorium You say "If you examine Wip/ve you can see the non-optimized command we put together to produce a shuffled deck of 52 cards." You say "Wip/vd is the command to create an ordered deck." Sir_Isaac traces the code.. Sir_Isaac says "OK, but why the underscores?" You say "Okay, thats to do with the return value from the shuffle command" You say "For example [shuffle(1 2 3 4 5 6 7,3)] returns 1_2_4_7: 3 6 5" You say "And shuffle has a limit of 17 shuffled items." Sir_Isaac is beging to see.. Sir_Isaac says "Right.. Ok." You say "We need therefore to store the intermediate steps with 17 items taken from 52, and then operate on the first() of this to give something we can shuffle again." Sir_Isaac says "So it comes out in actually 3 different shuffles, leaving the one remaining card?" Ve:$shuffle:new deck;@xb me=[shuffle(get(me/xa),13)];@xc me=[shuffle(de_(first(get(me/xb))),13)];@xd me=[shuffle(de_(first(get(me/xc))),13)];@xe me=[shuffle(de_(first(get(me/xd))),13)];@xf me=[rest(get(me/xb))] [rest(get(me/xc))] [rest(get(me/xd))] [rest(get(me/xe))];@xg me=[edit(get(me/xe),:,spc(1))] Mark_Farrell breaks down ve... You say "@xb me=[shuffle(get(me/xa),13)];" You say "That's the standard shuffle to take 13 random cards from the 52 in the ordered deck in va. Register XB is set to the result." You say "XB: 20_22_23_25_26_27_28_29_33_34_35_36_37_38_40_41_42_44_45_65_66_67_68_69_70_71_73_75_76_77_129_131_134_135_136_138_139_140_141: 21 19 72 18 39 130 74 133 24 132 43 137 17" You say "So, XB is a single 'word', followed by a :, followed by 13 randomly selected cards." *Mark_Farrell* Time : Fri Oct 27 19:21:45 1995, Stardate : 95819.8 19:21:45 Sir_Isaac says "Word?" You say "wip/xb" Sir_Isaac says "Ohh, the underscores.." You say "20_22_23_25_26_27_28_29_33_34_35_36_37_38_40_41_42_44_45_65_66_67_68_69_70_71_73_75_76_77_129_131_134_135_136_138_139_140_141: 21 19 72 18 39 130 74 133 24 132 43 137 17" You say "So that is a 'word' as it has no spaces." Sir_Isaac says "One really long word because of the underscores.." Mark_Farrell nods. You say "So, the next command is: @xv me=[shuffle(de_(first(get(me/xb))),13)];" Mark_Farrell means @xc, not @xv Sir_Isaac nods. You say "So, this sets xc to the result of the functions on the right hand side." You say "The rule for working you what it does is to work outwards from the centre." Sir_Isaac says "Aye." You say "So, we have 'get(me/xb)' to return the entire result of the first shuffle we did." You say "We then take the 'first()' of it - ie just the list of remaining cards separated by underscores." Sir_Isaac says "Right. That would only yield the word.." Sir_Isaac is begining to understand. You say "We then 'de_()' it, which replaces the underscores with spaces, to give us a list again, and then finally we 'shuffle()' again." Sir_Isaac says "I'm unfamiliar w/ de_().." You say "Well, consider a basic case - 'de_(1_2_3_4 5 6 7 8 A_b_c)'" You say "This returns 1 2 3 4 5 6 7 8 A b c" You say "Ie, it replaces all the underscores with spaces." Sir_Isaac says "Ok, as in DEstroy _ ?" Mark_Farrell grins. You say "Something like that - there is a complimentary function - put_()" Sir_Isaac says "Makes sense, no? :)" Mark_Farrell nods. Sir_Isaac guesses that PUTs _ into the string.. You say "Yup." You say "put(1 2 3 4) -> 1_2_3_4" You say "And it'd even work if I'd have typed put_()" Sir_Isaac examines wip again Mark_Farrell smiles. Shelley has arrived. Sir_Isaac stands to attention. You say "Good evening Shel." Shelley says "Carry on" Shelley says "Hiya Mark." Sir_Isaac says "Aye." Sir_Isaac relaxes slightly and continues his examination of the WIP.. You say "So, we had just about finished looking at the basic shuffle." Shelley waves Shelley leaves the Auditorium. Shelley has left. You say "Do you have any questions about it, Issac?" Sir_Isaac says "Aye, I still don't get hte details, but the log from the last lecture should iron it out." Mark_Farrell nods. You say "I set a homework exercise at the end of the last lecture to get people to try to think of better ways to shuffle the whole deck, using fewer @commands, and resiters." Mark_Farrell thinks maybe that was a bad idea and scared off a lot of people :-) Sir_Isaac says "Heh.. Not me sir, I wasn't there. :)" Sir_Isaac says "Wish I was, though. Woulda eaten up the time I spend just sitin' on the bridge.." Mark_Farrell smiles. You say "Okay, well, for the record, the shuffle can be done with 1 @command, and no extra attributes are needed." Sir_Isaac says "Really?" Mark_Farrell nods. You say "It's an evil little bit of code that I'm saving for a bit later in the course." Sir_Isaac says "Well, those scared off will miss out. :)" Mark_Farrell smiles. You say "Okay.... Let me give you the code then... (searches his multiple bits of paper)" Edredi has arrived. Edredi enters from the Quad. You say "This will take me a little bit of time to type in :-)" Vf: Sir_Isaac says "It's ok, I'll stick it out like the rest of 'em." Sir_Isaac :) Mark_Farrell smiles. Sir_Isaac notices Edredi enter. "C'mon over, interested in coding?" You say "WEll, the hints are that it uses iteration (iter2() function) and recursive calling." Sir_Isaac thinks about it.. Edredi has disconnected. Edredi has connected. Mark_Farrell smiles. Sir_Isaac says "Hmmm.." *Mark_Farrell* Cadet Edredi is looking at you. You say "So, shuffling aside, lets move ahead a bit in the functional stakes for the game." Sir_Isaac nods. You say "So, we now have a shuffled deck of 52 cards. Next thing to think about is how we are going to deal them out." Edredi leaves the Auditorium. Edredi has left. You say "Okay - any ideas on how to do it?" Sir_Isaac says "Pull the cards from the top of the register?" You say "Right. So, everytime you need a card, you just take the 'first()' and remove it from the list." Sir_Isaac says "Wait a sec.. Shouldn't we move instead of remove?" Sir_Isaac says "We gotta keep track somehow.." *Mark_Farrell* Time : Fri Oct 27 19:55:09 1995, Stardate : 95819.8 19:55:09 You say "Well, yes. There isn't a 'move' function though, so we would need to append it to a list of player's cards, and them remove it from the deck." Mark_Farrell nods. Sir_Isaac says "Right, just so long as the number doesn't get lost.." Mark_Farrell nods. Kheyrel has arrived. Kheyrel enters from the Quad. You say "Any other ways you can think of to do it?" Mark_Farrell smiles. "Evening." *Mark_Farrell* Cadet Kheyrel is looking at you. Name: Kheyrel(K'heyrel) Class: Cadet Race: Vulcan Sex: Male Org: StarFleet Title: Logged in for: 00:37 Idle for: 00:00 Kheyrel snaps to attention Sir_Isaac says "As you were." You say "I'm in the middle of giving a workshop on coding, Cadet, take a seat if you're interested, and 'at ease'" Name: Sir_Isaac(isc) Class: Ensign Race: Human Sex: Male Org: StarFleet Title: <<> :) Logged in for: 01:30 Idle for: 00:00 Kheyrel says "Thanks" Mark_Farrell pops Isaac one as I'm the senior officer :-) Sir_Isaac says "Aye, sorry, sir." Sir_Isaac looks at the floor with hands behind his back.. Sir_Isaac says "Almost instinctive." Mark_Farrell grins. You say "Good job I really don't have much truck with SFAing etc :-)" Kheyrel says "Sorry to interrupt Sirs, but who are in charge of Final exams?" You say "DC Shelley, of C Greene. The finals are given by TA's - of which I am one." Sir_Isaac says "BRB, sir." You say "If you need an unscheduled final, you must get it approved by Shelley or Greene." Mark_Farrell nods to Ensign Isaac. Kheyrel says "because I May have a problem, sir, due to RL constrain i may not be availlable to be at a schedule exam...!" Kheyrel says "Thanks Sir" Mark_Farrell nods. "If you get approval from Shelley or Greene, a TA will help you when it is convenient for the TA and yourself. Kheyrel says "Thanks And See you later" Kheyrel leaves the Auditorium. Kheyrel has left. WiP(#126vI) Work In Progress for Coding Workshop. A poker table. Owner: Mark_Farrell Credits: 1 Status: Thing Org: None(#-1) Type: Thing Flags: visible inherit Vd:$new deck:@xa me=[iter2(lnum(13),{[add(##,16)]})] [iter2(lnum(13),{[add(##,32)]})] [iter2(lnum(13),{[add(##,64)]})] [iter2(lnum(13),{[add(##,128)]})] Xa:17 18 19 20 21 22 23 24 25 26 27 28 29 33 34 35 36 37 38 39 40 41 42 43 44 45 65 66 67 68 69 70 71 72 73 74 75 76 77 129 130 131 132 133 134 135 136 137 138 139 140 141 Lock:Mark_Farrell(#16055PDeoqFc) Vb:16 Clubs 32 Diamonds 64 Hearts 128 Spades Va:$test *:@emit > %N types %0. The value returned is 'The [extract(v(vc),band(v(0),15),1)] of [lookin(v(vb),band(v(0),240),1)]'. Vc:Ace Two Three Four Five Six Seven Eight Nine Ten Jack Queen King Joker Race:Mechanoid Ulock:Mark_Farrell(#16055PDeoqFc) Xb:20_22_23_25_26_27_28_29_33_34_35_36_37_38_40_41_42_44_45_65_66_67_68_69_70_71_73_75_76_77_129_131_134_135_136_138_139_140_141: 21 19 72 18 39 130 74 133 24 132 43 137 17 Xc:22_23_25_26_28_29_33_34_35_36_40_44_65_68_69_70_71_75_76_77_129_131_138_139_140_141:: 66 134 38 41 67 73 20 45 136 27 42 37 135 Xd:25_26_33_36_40_44_65_68_69_70_131_138_139: 141:: 129 77 22 23 34 140 75 35 76 28 29 71 Xe:: 70 36 139: 33 65 44 26 138 40 69 68 131 25 Xf:21 19 72 18 39 130 74 133 24 132 43 137 17 66 134 38 41 67 73 20 45 136 27 42 37 135 141:: 129 77 22 23 34 140 75 35 76 28 29 71 70 36 139: 33 65 44 26 138 40 69 68 131 25 Xg:21 19 72 18 39 130 74 133 24 132 43 137 17 66 134 38 41 67 73 20 45 136 27 42 37 135 141 129 77 22 23 34 140 75 35 76 28 29 71 70 36 139 33 65 44 26 138 40 69 68 131 25 Ve:$shuffle:new deck;@xb me=[shuffle(get(me/xa),13)];@xc me=[shuffle(de_(first(get(me/xb))),13)];@xd me=[shuffle(de_(first(get(me/xc))),13)];@xe me=[shuffle(de_(first(get(me/xd))),13)];@xf me=[rest(get(me/xb))] [rest(get(me/xc))] [rest(get(me/xd))] [rest(get(me/xe))];@xg me=[edit(get(me/xe),:,spc(1))] Home: Ready Room Location: Carlin Auditorium RK'd has arrived. RK'd enters from the Quad. You say "Good evening, Cadet." You say "I'm giving a coding workshop if you'd like to take a seat." RK'd says "Good evening!" RK'd says "Sir." RK'd says "thankyou Sir, I would." You say "The lecture logs from the forst 3 are available via email if you would like a copy." RK'd sits down You say "It's not often that we have an artificial lifeform around the academy." RK'd says "ummm.... I would be most grateful Sir." Sir_Isaac has connected. Mark_Farrell notes the Isaac is idle at the moment, and we'll carry on when he wakes up. Sir_Isaac has disconnected. Sir_Isaac wakes up. Mark_Farrell grins. Sir_Isaac :) Saving TrekMUSE DataBase. Response will be slow for a few minutes. RK'd does his best to look insignificant. Sir_Isaac says "And just in time to catch the DB save lag, ohh boy!" You say "Okay, so, to recap, we have the deck of 52 cards, and a method to pop a card off the top of the deck when we need it." Sir_Isaac nods. RK'd wonders whether this is metaphorically or is there a eg object? You say "If you examine WiP/vf you will see some code for the method you put forward, in a very basic form." Mark_Farrell points at the Work In Progress :-) You say "$deal card:@xf me=[first(v(xe))];@xe me=[rest(v(xe))]" RK'd gives it a bit of a look. You say "That sets xf to be the next card on the deck, and then sets the deck (in xe) to be the 'rest()' of the deck, after we take the card out." Sir_Isaac says "Ok.." You say "That was more or less what you were suggesting, Isaac, but with the card being added to a players list of cards?" Sir_Isaac says "Aye." Sir_Isaac says "Maybe could leave a register for each player." Mark_Farrell nods. You say "We can set an arbitary limit of 5 players, and just have 5 registers" You say "So, before we go on with that, lets try to think of other ways of doing this." Sir_Isaac says "Or, we could just have a simple reaction to a question of 'How many players?'" Sir_Isaac thinks Mark_Farrell nods. "I was refering to the dealing process, rather than players" Sir_Isaac says "Aye, sorry." You say "As it stands we use 2 @ commands for every card we deal." You say "If possible we want to reduce that as much as possible." You say "Any more ideas on how we can handle dealing?" Sir_Isaac thinks some more.. Sir_Isaac's brain has been fried today, both literally and figureatively. Mark_Farrell chuckles. Sir_Isaac curses 440 live wires.. Sir_Isaac says "Volts, that is." You say "Okay, well, how about dealing out all the cards we are going to need at the start?" Sir_Isaac says "Well, we could just pop the first five off, and deal them that way." Mark_Farrell nods. Sir_Isaac shrugs, "So it's not the way they're really dealt, but it shouldn't make a difference anywayz." Sir_Isaac :) You say "This begs the question of 'do we need to pop them off' at all?" Sir_Isaac says "Hmmm.. I think I see where you are going.." RK'd says "one to each player rather than five to one player, surely?" You say "Can't we just remember player numbers, and have player 1 use the first 5, player 2 the next 5, and so on." RK'd is a bit of a purest when it comes to card games. Sir_Isaac says "Yep." Sir_Isaac says "Just reference them back to the origional register." RK'd says "you talking about pointers!" You say "RK'd - because the whole deck is shuffled randomly to start with, internally we don't need to deal them out independantly." You say "Aye, RK'd." Sir_Isaac says "That'll also give the advantage of having the whole deck in tact." Mark_Farrell smiles. Sir_Isaac nods. "Yep." Sir_Isaac :) You say "Aye. Keeping the whole deck intact means that we can avoid 2 @ commands for dealing each card, or block of cards." RK'd hmmms.... He isn't happy about the idea of using sheer randomness. Purely they should be dealt in the right order or at least seem to be. Sir_Isaac says "Who'll know the difference." Mark_Farrell nods at RK'd. "They will be. I'm just coming on to that. RK'd says "oh... appologies, Sir." RK'd bows You say "To recap: We can 1. Using 1 @command produce a completely random deck of 52 cards. (my optimized code)" Sir_Isaac nods. You say "2. We don't need to deal cards explicitly to players." RK'd will have to review it mor closely. You say "All we need to do, is remember how many cards a particular player is meant to have." Sir_Isaac says "A total of five." Sir_Isaac doesn't even want to begin to think about discards yet. :) You say "Right - so as we go around betting and dealing we just increment the number of cards that player has." You say "Discards are an interesting problem." Mark_Farrell smiles Sir_Isaac says "That would be where the two @ commands begin to looks better." Mark_Farrell shakes his head. Sir_Isaac says "Just drop off the discards, and put them on the bottom of the origional register/deck?" You say "We can still do it using the 'pointer' analogy, but it's a bit more complex." You say "Very close, Isaac." RK'd says "how so?" Sir_Isaac says "Ok... I see now.." You say "We need to throw the discards away, and fill the spaces with the new cards." Sir_Isaac has a vague sense of how. Mark_Farrell nods. You say "Right." Sir_Isaac says "Just slide the 'pointer' off of the discard and down to the next free card." Mark_Farrell nods. "That would be one way." Sir_Isaac just never seems to find the best way.. :( :) Cervus has arrived. Cervus enters from the Quad. You say "Instead of having player 1 using the first 5 cards on the deck, player 2 cards 6 to 10 - we can space them more fully by having the first 10 for player 1 - 5 first round cards, and upto 5 discards." RK'd raises the corners of his mouth. Sir_Isaac says "Aye, I see.." RK'd exclaims "Very clever!" You say "All we need to do to discard is rearrange those 10 cards." Sir_Isaac says "That can't be TOO difficult.." RK'd says "somewhat like a minny pack each." *Mark_Farrell* Time : Fri Oct 27 20:30:48 1995, Stardate : 95819.8 20:30:48 Mark_Farrell hasn't really thought about that bit in depth yet, but it shouldn't be too hard :-) You say "Aye, RK'd." Cervus leaves the Auditorium. Cervus has left. You say "Well, Isaac, finding the 'best' way takes some practice at what the game can do." You say "You need to understand the limitations of the game, and work to them." Sir_Isaac needs to practice, practice, practice if he ever wants to get to R&D Hall. RK'd says "which game do you refer to there? >:-)" You say "The primary concern with any project you do is to choose efficent methods for performing tasks." Mark_Farrell grins at RK'd - both - you need to understand the game of poker, and the muse engine to produce the object than plays poker, and is 'muse-friendly' RK'd raises the sides of his mouth in an affectation. You say "So, I want to leave it there for this week as far as the poker table is concenred." You say "Next friday, I plan to cover the issue of discarding, and showing players the cards." Sir_Isaac nods. "Aye, sir. You say "THe lecture will start at 6pm in here, as normal." RK'd is looking forward to system optimisation time. Mark_Farrell would appreciate it if you can spread the word. Sir_Isaac says "Aye, I will. Why don't you post to SFNEWS and SFANEWS too?" You say "Logs of the 4 lectures so far are available by +mailing me an email adddress, and the WiP is left visible" You say "It is of SFAnews, and I need to see someone about SFnews." Sir_Isaac nods. You say "The object number of the WiP is #126, and examine #126 will show you the code so far." You say "Even if the WiP is not in your location." Taken. Mark_Farrell puts a marker in his TF logs :-) Sir_Isaac says "Always easiest to find it then." Mark_Farrell smiles. Sir_Isaac shakes Mike_Farrell's hand. Mark_Farrell smiles and returns the handshake. You say "I hope that was useful." Sir_Isaac says "Well, sir, thank you. I hope to be here next week. :)" Kramton (ktn) pages: I made a replicator for my quarters...the replicator is part of the room. Sir_Isaac says "Have a good 'evenin, both." You page-posed Kramton with "Mark_Farrell smiles. Great.". Sir_Isaac walks down the aisle toward the exit. You say "G'night, Ensign." Sir_Isaac leaves the Auditorium. Sir_Isaac has left. Kramton (ktn) pages: I did get a little help from FedCode...I couldnt get it to put the order out...now it does..:) RK'd says "good night." You whisper-posed Kramton with "Mark_Farrell smiles. Anyway - coding the replicator into the room is a GoodThing(tm) as it saves having an extra object in there to do just that.". Kramton (ktn) pages: I know...I already have my two. RK'd looks exasperated. RK'd stands... RK'd says "excuse me Sir...." RK'd says "Is that 6 here. On this time?" You say "Aye." You say "you: say [time()]"