Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Principal Variation Search #141

Merged
merged 23 commits into from
Jun 7, 2024
Merged

Principal Variation Search #141

merged 23 commits into from
Jun 7, 2024

Conversation

michelle-lai-swl
Copy link
Collaborator

@michelle-lai-swl michelle-lai-swl commented Apr 4, 2024

Implemented pseudo-code described here: https://en.wikipedia.org/wiki/Principal_variation_search

Performs similar to negamax in most cases, but shows significant improvements in some cases.
Performance change: (used test_performance.py)

FEN: r1b2rk1/ppqn1pbp/6p1/3pp3/7B/2PB1N2/PP3PPP/R2QR1K1 w - - 0 16
PVS: 27345484 function calls (27283687 primitive calls) in 15.451 seconds
Negamax: 49480947 function calls (49373488 primitive calls) in 27.578 seconds

FEN: 8/8/8/8/5R2/2pk4/5K2/8 b - - 0 1
PVS: 19218758 function calls (19146750 primitive calls) in 9.663 seconds
Negamax: 20640107 function calls (20567047 primitive calls) in 10.045 seconds

FEN: r1b2rk1/ppq2ppp/3bpn2/3pP3/8/2PB2B1/PP1N1PPP/R2QK2R b KQ - 0 11
PVS: 84376165 function calls (84159373 primitive calls) in 47.843 seconds
Negamax: 79506308 function calls (79300989 primitive calls) in 43.080 seconds

Creds: Created with the wonders of Github Copilot with Kelvin's help

@michelle-lai-swl michelle-lai-swl linked an issue Apr 4, 2024 that may be closed by this pull request
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@claudiayip claudiayip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions for clarification

sporkfish/searcher/minimax.py Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
@ccjeremylo
Copy link
Collaborator

ccjeremylo commented Apr 4, 2024

Implemented pseudo-code described here: en.wikipedia.org/wiki/Principal_variation_search

Performs similar to negamax in most cases, but shows significant improvements in some cases. Performance change: (used test_performance.py)

FEN: r1b2rk1/ppqn1pbp/6p1/3pp3/7B/2PB1N2/PP3PPP/R2QR1K1 w - - 0 16 PVS: 27345484 function calls (27283687 primitive calls) in 15.451 seconds Negamax: 49480947 function calls (49373488 primitive calls) in 27.578 seconds

FEN: 8/8/8/8/5R2/2pk4/5K2/8 b - - 0 1 PVS: 19218758 function calls (19146750 primitive calls) in 9.663 seconds Negamax: 20640107 function calls (20567047 primitive calls) in 10.045 seconds

FEN: r1b2rk1/ppq2ppp/3bpn2/3pP3/8/2PB2B1/PP1N1PPP/R2QK2R b KQ - 0 11 PVS: 84376165 function calls (84159373 primitive calls) in 47.843 seconds Negamax: 79506308 function calls (79300989 primitive calls) in 43.080 seconds

Creds: Created with the wonders of Github Copilot with Kelvin's help

Wow this is impressive

Not quite clear to me the (subtle?) differences between PVS and NegaScout yet (or if they are actually the same thing?) - is NegaScout still in our "book of work"?

Looking at the issues, seems like they (PVS and NegaScout) are being lumped in together, i.e. #71

PS: did a quick visualisation of the fen strings, can't say I managed to reach any conclusion why sometimes PVS is so much faster, sometimes we get similar perf...

Copy link
Collaborator

@ccjeremylo ccjeremylo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks v good (good design good tests imo) - nothing blocking really

Left some very annoying/nitpicking comments, mostly v trivial (doc string and naming stuff)

Happy to approve if want to leave the changes in next PR

README.md Show resolved Hide resolved
config.yml Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/minimax.py Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
sporkfish/searcher/pvs.py Outdated Show resolved Hide resolved
@KYLChiu
Copy link
Owner

KYLChiu commented Apr 6, 2024

One overarching issue with this design (my fault) is that any underlying changes e.g. TT move ordering now needs to be implemented twice.

I have an idea on how to refactor it to save us form DRY (don't repeat yourself) - @michelle-lai-swl for next PR pls.

@richardhunghhw richardhunghhw self-assigned this Jun 7, 2024
@KYLChiu KYLChiu merged commit 9852ee1 into master Jun 7, 2024
1 check passed
@KYLChiu KYLChiu deleted the feature/pvs branch June 7, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Principal variation search / Negascout
5 participants