Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titsuki/raku-algorithm-zobristhashing
a hash function for board games
https://github.com/titsuki/raku-algorithm-zobristhashing
Last synced: 3 months ago
JSON representation
a hash function for board games
- Host: GitHub
- URL: https://github.com/titsuki/raku-algorithm-zobristhashing
- Owner: titsuki
- License: artistic-2.0
- Created: 2016-02-22T04:28:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-09T00:41:15.000Z (5 months ago)
- Last Synced: 2024-08-10T01:26:01.132Z (5 months ago)
- Language: Raku
- Size: 17.6 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
[![Actions Status](https://github.com/titsuki/raku-Algorithm-ZobristHashing/actions/workflows/test.yml/badge.svg)](https://github.com/titsuki/raku-Algorithm-ZobristHashing/actions)
NAME
====Algorithm::ZobristHashing - a hash function for board games
SYNOPSIS
========use Algorithm::ZobristHashing;
# the case input is Str
my $zobrist = Algorithm::ZobristHashing.new();
my $status = $zobrist.encode("Perl6 is fun");
my $code = $zobrist.get(0,"P"); # Int value which represents state h(0,"P")
my $code = $zobrist.get(5," "); # Int value which represents state h(5," ")# the case input is Array
my $zobrist = Algorithm::ZobristHashing.new();
my $status = $zobrist.encode([["Perl6"],["is"],["fun"]]);
my $code = $zobrist.get(0,"Perl6"); # Int value which represents state h(0,"Perl6")DESCRIPTION
===========Algorithm::ZobristHashing is a hash function for board games such as chess, GO, GO-MOKU, tic-tac-toe, and so on.
CONSTRUCTOR
-----------### new
my $zobrist = Algorithm::ZobristHashing.new(%options);
#### OPTIONS
* `max-rand => $max-rand`
Sets the upper bound number for generating random number. Default is 1e9.
METHODS
-------### encode(Str|Array)
my $status = $zobrist.encode("abc"); # h(0,"a") xor h(1,"b") xor h(2,"c")
my $status = $zobrist.encode([["a"],["b"],["c"]]); # h(0,"a") xor h(1,"b") xor h(2,"c")
my $status = $zobrist.encode([["ab"],["c"]]); # h(0,"ab") xor h(1,"c")Returns the hash value which represents the status of the input sequence. If the input value is the nested array, it flattens this and handles as a 1-dimensional array. If the input value is empty, it returns the type object Int.
### get(Int $position, Str $type)
my $status = $zobrist.encode(["abc"]);
my $code = $zobrist.get(0,"abc"); # in this case $code == $status
my $new-code = $zobrist.get(0,"perl"); # assigns a new rand value, since h(0,"perl") is not yet encodedReturns the Int value which represents the state(i.e position-type pair). If it intends to get the state not yet encoded, it assigns a new rand value to the state and returns this new value.
AUTHOR
======titsuki
COPYRIGHT AND LICENSE
=====================Copyright 2016 titsuki
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
This algorithm is from Zobrist, Albert L. "A new hashing method with application for game playing." ICCA journal 13.2 (1970): 69-73.