Live data from Hacker News

What happens when you make a move in lichess.org?

davidreis.me

51–60 of 162 posts

Re: What happens when you make a move in lichess.org?

#51
post #24

Beautiful architecture. Startups and companies like Netflix should learn from this instead of cargo culting microservices.

And what exactly do you think lila, lila-ws, and redis are if not microservices (or as they should be called, “services”)? Lichess could easily be implemented as a single monolithic process but it is not.

They are services, but not micro. lila-ws spun off of Lila for a good reason (fault isolation) and not because "let's make everything a service". And they don't follow any standard microservice pattern - a reverse proxy isn't a microservice.

Re: What happens when you make a move in lichess.org?

#52
post #44

nit: fen only encodes board state, not game state Edit: also includes move count but not repetition.

How is the game state not just the board state? Move history doesn’t matter in chess (FEN encodes the 50 move rule)

Per Wikipedia, it doesn't encode the threefold repetition rule.

https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notati...

Re: What happens when you make a move in lichess.org?

#53
post #49

Earlier quoted context omitted.

> Unfortunately, I'm afraid, drawing something like that during interview may not land a job at faang =( Yet another reason to be skeptical of the quality of hiring in faang if anything.

Why feel anything about it at all? You work at FAANG: be glad for the money or quit if there isn't any. You don't work at FAANG: bad hiring makes it easier for you to get hired and make money.

You haven't considered the third option: couldn't care less about working at these companies because of different reasons (personal, financial, geography, cv or whatever).

My criticism was mostly towards the very poor metrics these companies have introduced behind hiring, albeit I can understand that given the gigantic amount of applications they get a mechanism for removing false positives is acceptable even if missing on false negatives.

And even more that it spread to companies that do not have their problems and can't afford false negatives.

Re: What happens when you make a move in lichess.org?

#54
post #44

nit: fen only encodes board state, not game state Edit: also includes move count but not repetition.

How is the game state not just the board state? Move history doesn’t matter in chess (FEN encodes the 50 move rule)

Timing of moves

Re: What happens when you make a move in lichess.org?

#55
post #44

nit: fen only encodes board state, not game state Edit: also includes move count but not repetition.

How is the game state not just the board state? Move history doesn’t matter in chess (FEN encodes the 50 move rule)

Indeed, the 50 move rule, as well as castling rights, whose move it is, and whether any pawns are currently eligible for en passant.

Re: What happens when you make a move in lichess.org?

#56

I wish this discussed the timing arbitration of each move. Based on the packet information (if that is correct & complete) then the timing is done entirely on the clients. However, they show the time in seconds which can't be right so I am curious how accurate this packet schema is (or if those are float values). Regardless, one thing I find maddening about chess.com is the time architecture of the game. I haven't se…

Vladimir Kramnik agrees with your observations about chesscom.

I'm surprised to see anyone bring him up here!

Re: What happens when you make a move in lichess.org?

#57

Earlier quoted context omitted.

Overly complicated with microservices. Can be made 10x simpler.

Sometimes simplicity is not the best goal. Redundancy, scalability, decoupling, resilience, best possible handling of errors, cost optimization, etc. may be more important at the scale Netflix operates at.

For Netflix level of complexity. Pornhub has more traffic and serves more customer than Netflix with monolithic PHP and some services.

Re: What happens when you make a move in lichess.org?

#58
post #10

- "While these moves could be calculated client-side, providing them server-side ensures consistency - especially for complex or esoteric chess variants - and optimizes performance on clients with limited processing capabilities or energy restrictions." Just a wild guess: might be intended to lower the implementation barrier for new open-source software clients on new platforms, and/or preempt them from implementing…

For those curious about the illegal move, it seems like it's allowing queen side castling through the king side rook (or vice versa). eg. if this is the first rank, R _ _ R K _ _ _, then you could make the move O-O-O and end up with _ _ _ R K _ _ _ Naturally, it's not possible to view this move anymore, but this game ( https://lichess.org/XDQeUk6j#48 ) has everything up until the last legal move right before the ille…

Wow it just ate the rook huh?

Re: What happens when you make a move in lichess.org?

#59
> - l: Probably some length?

I don't understand why the author didn't just look this up in the source code. Lichess is open source and we can see exactly what this field is here, it's the average lag:

https://github.com/lichess-org/lila/blob/45b5f0cfbbf6c045ad7...

  send = (t: string, d: any, o: any = {}, noRetry = false): void => {
    const msg: Partial = { t };
    if (d !== undefined) {
      if (o.withLag) d.l = Math.round(this.averageLag);
      if (o.millis >= 0) d.s = Math.round(o.millis * 0.1).toString(36);
      msg.d = d;
    }
    if (o.ackable) {
      msg.d = msg.d || {}; // can't ack message without data
      this.ackable.register(t, msg.d); // adds d.a, the ack ID we expect to get back
    }

    const message = JSON.stringify(msg);
    ...
Which is calculated from how long the server takes to respond to ping messages that the client sends:

  private schedulePing = (delay: number): void => {
    clearTimeout(this.pingSchedule);
    this.pingSchedule = setTimeout(this.pingNow, delay);
  };

  private pingNow = (): void => {
    clearTimeout(this.pingSchedule);
    clearTimeout(this.connectSchedule);
    const pingData =
      this.options.isAuth && this.pongCount % 10 == 2
        ? JSON.stringify({
            t: 'p',
            l: Math.round(0.1 * this.averageLag),
          })
        : 'null';
    try {
      this.ws!.send(pingData);
      this.lastPingTime = performance.now();
    } catch (e) {
      this.debug(e, true);
    }
    this.scheduleConnect();
  };

  private computePingDelay = (): number => this.options.pingDelay + (this.options.idle ? 1000 : 0);

  private pong = (): void => {
    clearTimeout(this.connectSchedule);
    this.schedulePing(this.computePingDelay());
    const currentLag = Math.min(performance.now() - this.lastPingTime, 10000);
    this.pongCount++;

    // Average first 4 pings, then switch to decaying average.
    const mix = this.pongCount > 4 ? 0.1 : 1 / this.pongCount;
    this.averageLag += mix * (currentLag - this.averageLag);

    pubsub.emit('socket.lag', this.averageLag);
    this.updateStats(currentLag);
  };

Re: What happens when you make a move in lichess.org?

#60

I wish this discussed the timing arbitration of each move. Based on the packet information (if that is correct & complete) then the timing is done entirely on the clients. However, they show the time in seconds which can't be right so I am curious how accurate this packet schema is (or if those are float values). Regardless, one thing I find maddening about chess.com is the time architecture of the game. I haven't se…

> it feels like the SERVER is tracking the time

TBH this is what I expected for all online chess. How else to reconcile the two players' differing clocks and also prevent client-side cheating?

Post reply on HN