How did you learn web development?

Interesting! I thought JavaScript always treated numbers as floating point (where large numbers do not wrap around). But TIL bitwise ops specifically treat it as 32-bit int!

2**31 // 2147483648
1<<31 // -2147483648
5 Likes

Wow. I guess that can give us a horrible JS equivalent of Euler’s identity:

(2**31)>>31 // -1
4 Likes

That’s such a JS thing :joy:

3 Likes

okay this is one of those things where i become progressively more confused starting with the first sentence :joy:

These look like awesome reading though!! I’m adding them to my reading list. I’ve heard of Deep Learning and the Game of Go before, so it’s cool to hear it mentioned again. It seems really interesting. Will it still hold up? It’s 6 years old now. I have no real concept of how quickly these things change :see_no_evil:

1 Like

I was just picking a somewhat technical topic, that I wouldn’t read, but maybe if I needed to double check something specific about it, I might dip into Wikipedia, partly because it’ll pop up as a fairly high search result.

I had a friend that went deeper into that book than me and tried to apply the methodology to tafl games.

I think some of the concepts should still be fine, but maybe there’s things that will be sped up and replaced.

I suppose various libraries change, some things are buggy, some things less buggy as software changes. It’s hard to know exactly without just doing it again.

I wanted to do it myself for some small combinatorial games also, I just got sidetracked with other things :slight_smile:

1 Like

It’s just the mathematical way of saying “There’s always a twirl in your hair”. It’s one of my favourite theorems because of its funny name :smile:

4 Likes

So I’ve finally started reading Deep Learning and the Game of Go, and I’m trying to learn TypeScript along the way by implementing the Python code in TS. But there are some Python syntax things I’m not really sure if I’m understanding, and I was wondering whether any of y’all might be able to point me in the right direction.

The very first example (Chapter 3, Listing 3.1, Page 31: ‘Using an enum to represent players’; python code available here):

class Player(enum.Enum):
    black = 1
    white = 2
    
    @property
    def other(self):
        return Player.black if self == Player.white else Player.white

It’s not entirely clear to me why an enum can have a method attached to it. In TS, the closest way I can figure to implement this is:

export namespace Player {
    export enum Color {
        black = 1,
        white,
    }

    export function other (player: Color) {
        return player === Color.black ? Color.white : Color.black;
    }
}

Does this seem like a reasonable use of namespace in TS? I can’t figure another way to meaningfully group the function and the enum.

Also, does one bother with JSdoc in TypeScript the same way as with JavaScript? Or would you omit it, since the typing is explicit?

The other point of uncertainty I had is the use of the logical XOR in the Move() class (chapter 3, Listing 3.3, page 32: ‘Setting moves: plays, passes, or resigns’; code available here):

class Move():
    def __init__(self, point=None, is_pass=False, is_resign=False):
        assert (point is not None) ^ is_pass ^ is_resign

Doesn’t chaining XORs like that mean that it will pass the assertion if any one of them is true or if all of them is true? That doesn’t seem especially useful to me. Are we just assuming that we’ll never initialize Move() with exactly 3 truthy arguments?

4 Likes

ML in TS?? I’m curious how it goes. I’ve heard of people doing it, but the math libraries in Python (numpy, scipy etc.) are so nice I couldnt imagine another way.

As far as translation goes, I think you’ve done it about right. There are a lot of options really.

You keep the documentation, but omit the types. Check out the example on this page:

I agree, looks like a bug. (Though maybe there’s some context I’m missing)

Better to assert something like:

sum(1 for cond in (point is not None, is_pass, is_resign) if cond) == 1
2 Likes

oh no lol, the book doesn’t actually get into machine learning until a fair bit later!! i’m just trying their implementation of game logic, GTP, and other Go-related utilities (which are quite different from my JS implementation) for now as an exercise in learning both python and typescript syntax :stuck_out_tongue: i will certainly give the ML part a shot in TS when i get to it, but i imagine i might switch back over to python at that point!

TSdoc tho!! More documentation tools!!! That is exciting ^^ thanks :slight_smile:

I wrote out a similar XOR function in TS that uses Array.prototype.reduce() and increments the accumulator with each truthy value, and returns result === 1. I don’t think TS/JS has a native assert thingy, but isn’t it basically equivalent to if (!assertion) throw new Error ()? Or does asserting throw more useful errors?

5 Likes

Yes - there may be a common misconception about XOR, namely thinking of it as “exactly one is true” (which one may expect given an “exclusive or”).
But since XOR is associative (which is why no parantheses are needed for a ^ b ^ c), it can be generalised to a multivariate operator. Then this translates to “an odd number of variables is true”, and I feel like it’s helpful to remember it in this way.

4 Likes

Oh cool! Then I think TS is a fine language to work in :slight_smile:

If you’re looking for something applied, a lot of this stuff exists in online-go/goban (uses TS). For example, here’s the color switching:

goban’s pretty legacy code, so lots of room for improvement IMHO.

There’s a healthy debate around error handling, and nuances for each language, so I don’t want to make a huge value judgement. A couple things to know though:

  • It’s true there’s no native assert in JS, but both Node.js and browsers support an assert API
  • throw gives the caller an opportunity to catch the error
  • assert is often compiled out in production, the assumption being that they are only useful if a developer is looking at the crash
4 Likes

Ogs also uses enums for player colors in the Goban repo

I think classes can have methods is the way I see it.

You could imagine making classes in typescript also.

I wonder could you also just have a particular file with a certain number of objects and related methods, and the file itself is a kind of grouping.

In the same way Goban stores a json go related things in one file and imports them as it needs them?

I think the typescript interface is like some kind of schema for objects.

Tbf I would listen to @benjito, because all the typescript I’ve learned so far has been to hack together something for OGS :stuck_out_tongue:

3 Likes