This should be relatively straightforward code, but the one thing that bears some explanation
is the game ???logic.??? As it turns out, if you have the opponent simply picking tiles at
random, the opponent will very nearly always lose because the player is, of course, intelligent
(presumably!), and this will beat random more times than not. So, I needed to introduce a little
bit of advantage to the computer opponent. The way I did this is that some percentage of
the time, the opponent will just magically choose the correct matching tile, if it??™s the second
CHAPTER 8 n DWR FOR FUN AND PROFIT (A DWR GAME!) 454
tile being chosen. Much more than 10 percent, and the opponent is just too good and will beat
the human purely almost every time (it was just trial and error to find the right value here). I
also increase that percentage with each match found, which kind of simulates a real player
who tends to remember tiles as he or she plays longer. Again though, incrementing the percentage
more than one percentage point per match tends to make the opponent too ???smart???
and too difficult to beat.
So, now that we??™ve seen the code for the flow between the client and server and back
again, I thought it would be helpful to see this in a graphic form, and Figure 8-9 is just such a
form.
Pages:
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776