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
5 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?

5 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
3 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

i finally learned about regex and i feel like i’ve unlocked forbidden knowledge.

this spicy search string matches any properly-formatted non-branching SGF tree

/\s*\((?:;\s*(?:[A-Z]+(?:\[(?:[^\\\]]|\\[\s\S])*\]\s*)+)*)+\)\s*/

mwahahahaha i am drunk with power

10 Likes

I think the thing that ends up being annoying about regex is that it’s always hard to know what kind of weird cases will also trigger in an unwanted way.

Like properly formatted in this case is something like has a certain pattern of letters and brackets and semi colons right?

But it wouldn’t tell you if B[zz] is valid given SZ[9] of a board, or if it’s using non-standard labels for the moves or information like komi etc.

So would it be like something isomorphic to an sgf structure?

I’ve never gotten good at, or remembered a few days after I’ve used regex for something what the regex means XD

It does seem fairly cool as a first pass at detecting if something is off.

4 Likes

Like I wonder what happens if you downloaded a game from fox where the players names are in Chinese or Korean etc :slight_smile:

2 Likes

what i meant by ‘properly-formatted’ is that it conforms to the EBNF definition on red-bean.

it doesn’t even check to see that the valuetypes are allowed in a given property; it would even match something like (;B[eleventy-1st\]Birthday!]).

so, it’s probably not the most practical thing for actually parsing things quickly & comprehensively :slight_smile:

6 Likes

Yeah I suppose, once you know what gets through it, suppose it’s a kind of rejection filter for error catching, then you can manage it afterward :slight_smile:

What did you use to learn about regex?

2 Likes

there’s a chapter in this book about regex!! i’ve never been especially good about finishing educational books, but i’m about halfway through this one, and i’m glad i’ve stuck with it!

beyond that, i’ve just been checking the MDN docs about JS-specific things, and using regex101.com for testing things.

6 Likes

On a related note, have you ever played Vim golf? :slightly_smiling_face:

2 Likes

i’ve heard of code golf and vim golf but i have tried no form of golf other than manual minigolf.

i am interested tho! is it something you do online?

i’d like to improve my vim skills - right now, i barely use any vim commands at all and prefer using my mouse (in vscode w/ neovim plugin) if i don’t know a command

edit: okay, looking at the vimgolf website doesn’t help much :see_no_evil: i can’t quite figure out how to install it. i think the only way to do it is with the command line, but i’ve forgotten my WSL password and therefore cannot install anything via command line, except w/ npm in Powershell.

i think i have an old laptop lying around somewhere collecting dust, maybe i’ll install ubuntu on it. it can be my vimgolf computer lol

1 Like