Skip to content

Commit

Permalink
Version Beta 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenpham committed Feb 2, 2022
1 parent d994397 commit 6c85ee2
Show file tree
Hide file tree
Showing 11 changed files with 428 additions and 179 deletions.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,31 @@ For examples of field names:
### Field values
Except for fields of identicals such EventID, SiteID, WhiteID, BlackID, values of other fields could be NULL.

### Popular fields in table Games
We suggest beside ID, FEN and move fields, Games should have following fields according to popular PGN tags:

```EventID, SiteID, Date, Round, WhiteID, WhiteElo, BlackID, BlackElo, Result, TimeControl, ECO, PlyCount```

### Other tag fields in table Games
When a game has some tags that are not in the above list, users can choose to create new fields to store information of those tags or not.


## FEN field
A FEN string of each game could be stored (FEN strings) in that field. If the game starts from start-position, it could be saved as a NULL string.


## Moves fields
All moves of a game could be stored in some forms in some specific fields as the below:
- Moves: all moves including all other information such as comments are stored as a single string
- Moves1: each move (except Queen move) is encoded as a 1 byte when a Queen move is encoded as 2 bytes. All moves (of a game) are stored as a binary array and then saved into the database as a blob
- Moves2: similar to Moves1 but each move is encoded as 2 bytes

- Moves: all moves including all other information such as comments are stored as a single string. For example:
```1.c4 e5 2.Nc3 Bb4 {A21: English, Kramnik-Shirov counterattack} 3.Nd5 Be7 4.Nxe7 Nxe7 5.d4 exd4 6.Qxd4 O-O 1/2-1/2```

- Moves2: each move is encoded as 2 bytes. The encode for chess: ```from | dest << 6 | promotion << 12```
- Moves1: each move (except Queen move) is encoded as a 1 byte when a Queen move is encoded as 2 bytes

All moves (of a game) in Moves1/Moves2 are stored as a binary array and then saved into the database as a blob.

The algorithms of Moves and Moves2 are very simple, developers can easily encode and decode using their own code. In contrast, the algorithm of Moves1 is quite complicated, deeply integrated into our code/library. It is not easy for developers to write their own encode/decode. Even Moves1 can create the smallest databases, consider using Moves and/or Moves2 instead, just for being easy to use by other libraries.


## Converting speed
Expand Down Expand Up @@ -247,12 +262,6 @@ white6 = 5
Because the language is very simple and input strings are typically so short, we implement its parser in a simple, straightforward way, using the recursive method. From an input string (query), the parser will create an evaluation tree. That tree will be evaluated at every chess position with the parameters as a set of bitboards of that position. The position and its game will be picked up as the result of the evaluation of the tree is true (not zero).


### Matching

```
SELECT g.ID, g.Round, Date, w.Name White, WhiteElo, b.Name Black, BlackElo, Result, Timer, ECO, PlyCount, FEN, Moves FROM Games g INNER JOIN Players w ON WhiteID = w.ID INNER JOIN Players b ON BlackID = b.ID WHERE g.Moves LIKE '1.d4 Nf6 2.Nf3 d5 3.e3 Bf5 4.c4 c6 5.Nc3 e6%'
```


## Sample databases
There are two sample databases in the samples project at:
Expand Down
Binary file not shown.
22 changes: 13 additions & 9 deletions projects/ocgdb.xcodeproj/xcshareddata/xcschemes/ocgdb.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand All @@ -53,11 +53,11 @@
<CommandLineArguments>
<CommandLineArgument
argument = "-pgn /Users/nguyenpham/bsg/BanksiaMatch/db/Carlsen.pgn"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-db /Users/nguyenpham/Downloads/carlsen.ocgdb.db3"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-export"
Expand All @@ -77,7 +77,7 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-db /Users/nguyenpham/Downloads/345.ocgdb.db3"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-db /Users/nguyenpham/Downloads/mb-3.45.ocgdb.db3"
Expand All @@ -97,7 +97,11 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-dup"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-plycount 40"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-o remove"
Expand Down Expand Up @@ -141,15 +145,15 @@
</CommandLineArgument>
<CommandLineArgument
argument = "-o printall;printfen;printpgn"
isEnabled = "NO">
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-o moves"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-o moves2"
isEnabled = "YES">
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "-o moves;moves2"
Expand Down
Loading

0 comments on commit 6c85ee2

Please sign in to comment.