###前提・実現したいこと
55将棋においてMagicBitboardの実装をしようとしているのですが、マジックナンバーの考え方や求め方で詰まっております。
変数型はint32bit(マスが25マスな為)
bitboardは以下のようであるとします。
C++
1// 0| 1| 2| 3| 4| 2// 5| 6| 7| 8| 9| 3// 10| 11| 12| 13| 14| 4// 15| 16| 17| 18| 19| 5// 20| 21| 22| 23| 24|
例えばですが、角が以下の位置にいる場合、
C++
1// ーーーーー 2// ーーーーー 3// ーー角ーー 4// ーーーーー 5// ーーーーー
利きは以下のようになりますが、
C++
1// ◯ーーー◯ 2// ー◯ー◯ー 3// ーーーーー 4// ー◯ー◯ー 5// ◯ーーー◯
欲しいそれぞれの◯をマジックナンバーをかけることで一つに集めて以下のようにしたいです。
C++
1//上位ビットに集める 2// ーーーーー 3// ーーーーー 4// ーーーーー 5// ーー◯◯◯ 6// ◯◯◯◯◯
仮にも乱数を使って求めることはできました。しかし、どれがどこのbitか分からない上に、角の利きを一つ消してどこがどのbitか確かめようと同じマジックナンバーをかけると集めたbitが散らばってしまいます。考え方がまず間違っているのかも知れません。どなたかご教授いただけませんか?
C++
1#include <string> 2#include <iostream> 3#include <random> 4#include <bitset> 5using namespace std; 6 7int magicNumber(){ 8 random_device rnd; 9 mt19937 mt(rnd()); 10 return mt(); 11} 12 13bool isSatisfy(int num){ 14 int partbit = num >> 23; 15 cout << static_cast<bitset<32>>(num) << " " << static_cast<bitset<32>>(0b11111111) << endl; 16 if(partbit == 0b11111111)return true; 17 else return false; 18} 19 20int main(){ 21 while(true) { 22 int num = 0b11111111; 23 int magicNum = magicNumber(); 24 if(isSatisfy(num*magicNum)){ 25 cout << magicNum << endl; 26 cout << static_cast<bitset<32>>(magicNum) << endl; 27 break; 28 } 29 } 30 return 0; 31}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/19 09:05