Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Help, Turn based Game like Chess, i can't do it

Discussion in 'Multiplayer' started by Doko, Aug 1, 2014.

  1. Doko

    Doko

    Joined:
    Aug 1, 2014
    Posts:
    4
    Hello,
    First of all, i 'm foreigner (korean) so my english skill is bad. please understand my situation. thank you

    i wanna make a game like chess. actually i wanna make a game like Heroes of might and magic series game.

    and it can be network.

    My plan is that 1server , 2 client connected to it. and each client can play a game.

    what i have done is that i used MasterServer and register a server ( because i 'm making game so i think 2 server is not needed).

    and A client ( it is bulided, so i can run window), connected well.

    A Object i created, this is like a piece in chess( is this right word? like Knight,Queen,KIng ),

    if i press my space bar in client, RPC is called and server make a object. so server has Object control

    so if, i mouse click in client, object is moving to destination.

    (object has Network view Component and Synchronization is Reliable)

    when object moved, this moved smoothly. i mean not teleport to destination.
    you know what i mean? not teleport, move smoothly

    but, this is synchronization is Reliable.. so there is a delay of time...

    so i think.

    when you see Server window, this object teleport to destination.
    but when you see client window, this obeject move to destination smoothly.

    this is more efficient i think.

    but this is not worked...

    i wanna to say so much things but my english skill is so bad that i can't say collectly....

    but i keep doing.

    so i do many things to run what i wanted...

    this object is only exist in server. because i do like that.. using RPC.
    so in client, i can't control this obejct ( and i think this is good for security i think i heard of that)

    but, i really can't do that. so i think

    client has also a List which stored object(server has a list before).

    but i realize this is not good...

    when i control server, i can't access client list,
    when i control client, i can't access server list.

    this make same problem.... adding a list to client or not..

    this is turn based so i think synchronization doesn't need to be very soon.
    how can i do that?

    my question isn't clearly i think... but help me.

    i have searched korean cumunity, but no one can tell me that.. or make me confused...

    thank you for reading my bad word
     
  2. Doko

    Doko

    Joined:
    Aug 1, 2014
    Posts:
    4
    ah! i forgot to say, i used unity built-in network ...
    i never used photon network or others... i think my game is so light that i think i don't need to use others..
     
  3. Freezy

    Freezy

    Joined:
    Jul 15, 2012
    Posts:
    234
    Here's what I did:

    - RPC calls (read up)
    - create an enum with all the different multiplayer steps you need
    - create a state machine that controls the flow around the idea that both players remain synced
    - create seperate RPC calls for each state

    create a variable that stores the current state and one for a received state

    upon receiving an RPC call, put it's state into the received state

    in the state machine, upon reaching a state, send the message once (and only once)
    then check if you already received the message from the other side, or if you need to wait a bit

    upon receiving the proper reply from the other side, continue to the next state and repeat

    Code (CSharp):
    1.  
    2. //pseudo code
    3. chessstates state;
    4. chessstates sent;
    5. chessstates received;
    6.  
    7. enum chessstates : int{
    8.     connecting = 0,
    9.     start = 1,
    10.     white = 10,
    11.     black = 20
    12. };
    13.  
    14. void Update(){
    15.     switch (state){
    16.     case white:
    17.         if(sent != white)
    18.         {
    19.             //send white data (or wait for the player to make a move, then send)
    20.  
    21.             object[] data;
    22.             networkView.RPC( state.ToString(), RPCMode.OthersBuffered, data );
    23.          
    24.             //then set the reminder
    25.             sent = white;
    26.         }
    27.         else if (received == white ){
    28.             //save to goto black now
    29.         }
    30.         break;
    31.         case black:
    32.         if(sent != black)
    33.         {
    34.             //repeat white
    35.         }
    36.         break;
    37.     }
    38.  
    39. }
    As the rules are clearly defined, both server and client can check for invalid moves.
    So all you would need to know is what piece (give it a unique id) goes where (place on grid)

    Then play it like an animation locally