#include <iostream>
#include <bitset>
using namespace std;
// たとえば、マップ上で水があって進めない状態のフラグ
const unsigned MAP_WATER = ( 1 << 16 );
// たとえば、謎の力で進めない状態のフラグ
const unsigned MAP_UNKNOWN_POW = ( 2 << 16 );
// 1 : 何か物がある
// 0 : 普通の地面
int map[ 4 * 4 ] =
{
0, 0, 1, 0,
0, 0, 0, 1,
1, 0, 0, 0,
0, 1, 0, 0
};
// たとえば、 map[ 2 * 4 ]上に水を置きたいとき
void SetWaterFlag()
{
map[ 2 * 4 ] |= MAP_WATER;
}
// 水がなくなって、通れないフラグを解除したいとき
void ResetWaterFlag()
{
map[ 2 * 4 ] &= ~MAP_WATER;
}
void SetUnknownPowerFlag()
{
map[ 3 * 1 ] |= MAP_UNKNOWN_POW;
}
void ResetUnknownPowerFlag()
{
map[ 3 * 1 ] &= ~MAP_UNKNOWN_POW;
}
void PlayerAction()
{
// プレイヤーの位置を水の上とした時
// 分かりやすいように二進数で表示
cout << "map" << endl;
cout << std::bitset< 32 >( map[ 2 * 4 ] ) << endl;
auto val = 0xFFFF0;
cout << "0xFFFF0" << endl;
cout << std::bitset< 32 >( val ) << endl;
cout << ( 0xFFFF & map[ 2 * 4 ] ) << endl;
if( map[ 2 * 4 ] & MAP_WATER ) {
cout << "水があっていけない" << endl;
} else {
cout << "いける" << endl;
}
cout << "map" << endl;
cout << std::bitset< 32 >( map[ 3 * 1 ] ) << endl;
if( map[ 3 * 1 ] & MAP_UNKNOWN_POW ) {
cout << "謎の力があっていけない" << endl;
} else {
cout << "いける" << endl;
}
}
int main()
{
SetUnknownPowerFlag();
SetWaterFlag();
PlayerAction();
ResetWaterFlag();
ResetUnknownPowerFlag();
PlayerAction();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Yml0c2V0PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIOOBn+OBqOOBiOOBsOOAgeODnuODg+ODl+S4iuOBp+awtOOBjOOBguOBo+OBpumAsuOC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