![]() |
![]() |
||
Networked Worlds: Chess
Below are snippets of code that are necessary to use Connect15 to synchronize networked worlds. To include the Connect15
library in your Alice world, put the following line at the beginning
of your script:
This line gives you access to the Connect15 library. The next step is to create an array of the objects that will need to be synchronized in the networked world and tell Connect15 to keep these objects at the same position in all networked copies of the world. For the 3D Chess World, the chess pieces need to appear at the same position in the world for both players so that each player can observe the board position (much as they would if they were playing chess across a table rather than across a network). A shortened list of objects for the chess world appears below: transformables
= [blackBishop._composite,
connect15.SetTransformables(transformables) Obviously, this is an incomplete list; it is necessary to include all the pieces that need to be synchronized across Alice worlds. The line the follows the declaration of the transformables array tells Connect15 that the objects in the transformables array must be synchronized across the Alice worlds. The next step is to declare which player is allowed to move a given piece. In the 3D Chess world, there is an obvious way to partition the pieces; one player has permission to move the white pieces, the other player can move only the black pieces. This can be accomplished in the following way: if
Black:
else:
In the above example, the ownership of each piece is set using a variable Black. This variable has a different value depending on the player; in other words, in one player's world Black is set to 1, in the other, Black is set to 0. Based on black, a series of connect15.SetTag commands are executed. The SetTag command basically just tell connect15 to assign control of a particular piece to the computer issuing the command. So, for connect15.SetTag(0,1), we have assigned control of the 0th piece in the transformables array (blackBishop_composite) to the player for whom Black is 1. The final code snippet defines the messages that will be passed between the Alice worlds and initiates communication between them. def
ExecAndBroadcastString (message):
def
ReceiveMessages ():
Listen
= Do(ReceiveMessages,eachframe)
listen.start()
|
|||
|
Questions about this site? Contact the Webmaster |