github.com/frankkopp/FrankyGo@v1.0.3/internal/history/history.go (about) 1 // 2 // FrankyGo - UCI chess engine in GO for learning purposes 3 // 4 // MIT License 5 // 6 // Copyright (c) 2018-2020 Frank Kopp 7 // 8 // Permission is hereby granted, free of charge, to any person obtaining a copy 9 // of this software and associated documentation files (the "Software"), to deal 10 // in the Software without restriction, including without limitation the rights 11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 // copies of the Software, and to permit persons to whom the Software is 13 // furnished to do so, subject to the following conditions: 14 // 15 // The above copyright notice and this permission notice shall be included in all 16 // copies or substantial portions of the Software. 17 // 18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 // SOFTWARE. 25 // 26 27 // Package history provides data structures and functionality to manage 28 // history driven move tables (e.g. history counter, counter moves, etc.) 29 package history 30 31 import ( 32 "strings" 33 34 "golang.org/x/text/language" 35 "golang.org/x/text/message" 36 37 . "github.com/frankkopp/FrankyGo/internal/types" 38 ) 39 40 var out = message.NewPrinter(language.German) 41 42 // History is a data structure updated during search to provide the move 43 // generator with valuable information for move sorting. 44 type History struct { 45 HistoryCount [2][64][64]int64 46 CounterMoves [64][64]Move 47 } 48 49 func (h History) String() string { 50 sb := strings.Builder{} 51 for sf := SqA1; sf < SqNone; sf++ { 52 for st := SqA1; st < SqNone; st++ { 53 sb.WriteString(out.Sprintf("Move=%s%s: ", sf.String(), st.String())) 54 for c := White; c <= 1; c++ { 55 count := h.HistoryCount[c][sf][st] 56 sb.WriteString(out.Sprintf("%s=%-7d ", c.String(), count)) 57 } 58 m := h.CounterMoves[sf][st] 59 sb.WriteString(out.Sprintf("cm=%s\n", m.StringUci())) 60 } 61 } 62 return sb.String() 63 } 64 65 // NewHistory creates a new History instance. 66 func NewHistory() *History { 67 return &History{} 68 }