Networked and Mobile Gaming, 2014/15

Assignment 2


You have been shown a naive implementation of a two-player Pong game in class. In this assignment, your task is to improve the implementation so as to improve the consistency and responsiveness of the game, while at the same time reduce the visual disruption and jerkiness of the entity movement in the game.


You should work in a team of two for this assignment.

Deadline and Submission

Zip up a copy of your code (without node_modules subdirectory) and your assignment report in PDF format into a single zip file named
A01234567X-A9876543Y-A2.zip (replace A01234567Y and A9876543Y with your own matric number) and upload it into IVLE workbin, before 7 March 2015 (Saturday), 11:59pm.

Your Task

First, clone a copy of the git repo https://github.com/weitsang/nus-cs4344.git.

1. Local Lag

A naive implementation of local lag has been included. You can see these two lines of code in PongClient‘s onMouseMove() method.

setTimeout(function() {myPaddle.x = newMouseX;}, 100);
sendToServer({type:"move", x: newMouseX});

In this implementation, the local lag is fixed arbitrarily at 100ms.

It is unclear if a local lag of 100ms can be perceived and tolerated by players. Your job is to change this value to find the largest possible local lag that is tolerable by players. A proper method to find this tolerable threshold is to conduct a user study with many participants. In this assignment, however, you only need to determine this value based on your own judgement.

Note that a range of answers are acceptable — as long as the threshold you determine is not too large or too small. If you want to check the acceptability of your answer, run a simple user study with your friends and family.

Once the value is determined, implement the local lag properly in PongClient.js: (i) it should be a constant instead of a hard-coded magic number, (ii) it should consider the current delay between the client and the server.

Report this value in your assignment report, and a short description of you determine this value.

2. Hold and Wait

In the naive implementation, the client and the server both simulate the ball and determine the ball’s velocity after bouncing off a paddle (checkForBounce). If the velocity of the ball is different in the client and in the server, it could lead to inconsistent states between the server and the client. Trying to fix this inconsistency would lead to visual disruptions such as curved ball movement or teleported ball.

To fix this, you should change the client so that it holds the ball whenever the ball hits the paddle, and wait for the decision (updateVelocity message) from the server.

This solution would create a visual disruption (a minor one) where the ball sticks to the paddle for a short period of time. The longer the network latency is, the more noticeable and annoying this becomes.

Bonus: try playing a sound when the ball hits the paddle. Does it prolong the periodic in which the ball sticks to the paddle without noticeable?

3. Local Perception Filter

Finally, you should implement the local perception filter at the client so that the ball’s velocity is adapted according to the network latency.

4. Tolerable network delay

With all three techniques above implemented, how much network latency can the game tolerate?

Report this number in your report.


Your report should include the information requested above, as well as point to sections of the code that you have changed to implement the solution. A short explanation of each change is expected.

The total length of the report excluding front cover should be no more than 5 pages.


  • There is no need to synchronize the clock between the server and the client for this assignment.
  • You don’t have to measure the delay from the client to the server. When you need to get the delay, you can retrieve the value from the member delay at the client, and using the method getDelay() from a player object at the server.
  • There is a 20% jitter that is being introduced by the delay simulation code. Your solution should handle this jitter.
  • In case there are bug fixes to the skeleton code, you can do a git pull to fetch and merge the changes to your own version.
  • [!!] Please don’t fork and commit your solution into GitHub for everyone to see. Like all your other homework, you should keep it private until the homework is over.


Print Friendly, PDF & Email


  1. Hi Prof Ooi,
    I have read the code, but I found the client is just rendering the paddle and ball and listening to the server for any update of paddle and ball positions. I did not find any code for client to simulate the ball. Are we suppose to implement the simulation of ball at client side ourselves?

  2. Hi,

    My paddle moves to left constantly on the other players’ screen(so does the paddle in server) although I do not move my paddle at all. And the paddle on my screen does not move. (But the other player who is hosting the game server and playing game is ok) Any one gets the same problem?

Leave a Reply

Your email address will not be published.


© 2021 CS4344

Theme by Anders NorenUp ↑

Skip to toolbar