How to calculate the PST accurately?

Discussion of chess software programming and technical issues.

Moderator: Ras

janggi-korea
Posts: 14
Joined: Wed Jul 06, 2022 2:05 pm
Full name: baek-sc

How to calculate the PST accurately?

Post by janggi-korea »

Does anyone know how to calculate the PST accurately?
e.g.) win/lose
Piece capture?
Can you tell me the formula for the calculation?
안녕하세요?
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: How to calculate the PST accurately?

Post by algerbrex »

Do you mean piece-square tables? I don't think you do, but just in case: PSTs are generally created either by hand selecting values based on basic chess principles (knights towards the center, rooks on the central files, etc.) or automated tuning, like Texel tuning.
janggi-korea
Posts: 14
Joined: Wed Jul 06, 2022 2:05 pm
Full name: baek-sc

Re: How to calculate the PST accurately?

Post by janggi-korea »

Can you tell me your think about my tuning method?

1. Prepare a PGN of about 20,000~ games.
2. Calculate the statistics of the number of times each piece has moved to a specific square. (Number of wins/losses)
3. Calculate : win square - losse square
4. If the number of wins is + in the square position, it is judged as a good position. If it is -, it is judged as a bad position.
5. Then enter this value as the PST value.

* For this statistic, the number of winning and losing PGN games should be the same.
안녕하세요?
User avatar
Bo Persson
Posts: 259
Joined: Sat Mar 11, 2006 8:31 am
Location: Malmö, Sweden
Full name: Bo Persson

Re: How to calculate the PST accurately?

Post by Bo Persson »

janggi-korea wrote: Mon Jul 18, 2022 5:17 pm Can you tell me your think about my tuning method?

2. Calculate the statistics of the number of times each piece has moved to a specific square. (Number of wins/losses)
A square can be "good" for a piece at different phases of the game. For example, the king is safe in the corner in the early game, but might be strong in the center once the other pieces are gone.

So what is the average score of this?
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: How to calculate the PST accurately?

Post by algerbrex »

janggi-korea wrote: Mon Jul 18, 2022 5:17 pm Can you tell me your think about my tuning method?

1. Prepare a PGN of about 20,000~ games.
2. Calculate the statistics of the number of times each piece has moved to a specific square. (Number of wins/losses)
3. Calculate : win square - losse square
4. If the number of wins is + in the square position, it is judged as a good position. If it is -, it is judged as a bad position.
5. Then enter this value as the PST value.

* For this statistic, the number of winning and losing PGN games should be the same.
I don't think that'll work very well, mostly for the reason Bo pointed out.

But on top of that, I'm not sure how well the win/loss difference for a given square correlates to a good centipawn value for said square. A certain square might be very good to put your pieces on, and so it receives a large bonus, a bonus which may be too large and not play nicely with the other evaluation terms.
jhaglund2
Posts: 66
Joined: Mon Jan 16, 2017 6:28 pm

Re: How to calculate the PST accurately?

Post by jhaglund2 »

You could just have use array(s) with all the moves, with counters. They go into another array if they loss or draw and just add them as you parse the PGN. Then, subtract the two array squares for the particular piece, for the particular color, on the particular square.

If you decide the move is "good" based on the result of the game, then 1-0, means all moves for white are good.
You could create a small sample with pretermined values.

You could keep track in 3 basic ways with each color.
1) All pawns
a) win
b) losses
c) draws (optional)
2) Just the File pawn
a) win
b) losses
3) Just the Square of pawn
a) win
b) losses



Different ways to you could count...
int black_pawn_map[64]
int black_pawn_win_map[64]
int black_pawn_lose_map[64]
int black_pawn_sq[64]
int black_e_file_pawn[8]
int black_e4_pawn[1]

int black_pawn_map[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
...
int win_white_e_pawn_map[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};

int loss_white_e_pawn_map[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
...

You can do this for each piece and square.

int win_white_e_pawn_map[64] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 9, 0, 0, 0,
0, 0, 0, 0, 8, 0, 0, 0,
0, 0, 0, 0, 7, 0, 0, 0,
0, 0, 0, 0, 6, 0, 0, 0,
0, 0, 0, 0, 2, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};

or

int win_white_e_file_map[8] = {
0,5,4,4,6,3,2,0
};
...
int win_white_e5_pawn_map[1] = {
6
};
int loss_white_e5_pawn_map[1] = {
3
};

int win_black_e5_pawn_map[1] = {
7
};
int loss_black_e5_pawn_map[1] = {
5
};

score = win_white_e5_pawn_map[1] - loss_white_e5_pawn_map[1]
score = win_black_e5_pawn_map[1] - loss_black_e5_pawn_map[1]
w_score: 3
b_scrore: 2

score = w_score[sq] - b_score[sq]
score: 1


In any case, however you keep track, you create a table for wins and subtract it with the losses.

Create a PGN parser and counter tables.
Parse 1 PGN and check your tables.
Substract the tables to get your PST.
Repeat until end of PGN file.

Hope this helps some.
janggi-korea
Posts: 14
Joined: Wed Jul 06, 2022 2:05 pm
Full name: baek-sc

Re: How to calculate the PST accurately?

Post by janggi-korea »

I'm going to try about traditional Korean chess (Name: Janggi).
Your answers are very helpful to me.
In Janggi, I think it is easy to estimate the price because King and advisor cannot move out of the palace. There are only nine positions.

int black_king_map[9] = {
0,0,0
0,0,0
0,0,0

For the rest of the pieces, we will try to use tracking mapping according to the size of the board.
The only concern is that by repetition many movement scores are included in a particular square, or that the engine and engine confrontation pgn have almost the same movement route.

make a Korean-chess engine is technically very difficult. :D
I couldn't refer to CPW because no one knew the exact way. :oops:
안녕하세요?
jhaglund2
Posts: 66
Joined: Mon Jan 16, 2017 6:28 pm

Re: How to calculate the PST accurately?

Post by jhaglund2 »

Your answers are very helpful to me.
Glad to hear. :)
The only concern is that by repetition many movement scores are included in a particular square, or that the engine and engine confrontation pgn have almost the same movement route.
When you are parsing the PGN, you can also have some sort of repetition detection, and handle it however you want, such as discard those counters.

Like all variants of chess, you can probabaly comes up with a FEN position, and check to see if it had occurred more than once in the game while parsing.