Created
August 24, 2018 11:08
-
-
Save furai-no-ffff/731a24ab1a058477b85864d92bee17d5 to your computer and use it in GitHub Desktop.
一本道sim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImpasseTypes = [ | |
[0x11, 0x35], | |
[0x15, 0x31], | |
[0x11, 0x35], | |
[0x15, 0x31], | |
[0x11, 0x24], | |
[0x15, 0x22], | |
[0x24, 0x31], | |
[0x22, 0x35] | |
] | |
# biased shuffling | |
def shuffle_room(array) | |
(array.length-1).downto(0){| i | | |
x = rand(i+1) | |
next unless array[i] | |
next unless array[x] | |
array[i],array[x] = array[x],array[i] | |
} | |
array | |
end | |
def prune_room(array) | |
array.map{| v | | |
if not v or v >= 10 then | |
nil | |
else | |
v | |
end | |
} | |
end | |
def make_passages | |
array = [ | |
0, 1, 2, 3, 4, | |
5, 6, nil, 7, 8, | |
9, 10, 11, 12, 13 | |
] | |
prune_room(shuffle_room(array)) | |
end | |
def shop_exist?(passages, type) | |
type.any?{| coord | | |
x = (coord & 0xF) - 1 | |
y = (coord >> 4) - 1 | |
idx = y * 5 + x | |
passages[idx] | |
} | |
end | |
ImpasseTypes.each_with_index{| type,i | | |
shop = 0 | |
type = ImpasseTypes[i] | |
100_000.times{ | |
shop += 1 if shop_exist?(make_passages, type) | |
} | |
puts "#{i}: #{shop}" | |
} | |
__END__ | |
0: 92861 # 行き止まりが左上・右下 | |
1: 94205 # 右上・左下 | |
2: 92867 # 左上・右下 | |
3: 94159 # 右上・左下 | |
4: 94261 # 左上・中央右 | |
5: 94375 # 右上・中央左 | |
6: 94298 # 左下・中央右 | |
7: 92716 # 右下・中央左 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment