Skip to content

Instantly share code, notes, and snippets.

@Debilski
Last active June 9, 2019 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Debilski/c31b9f131f51d9f38f1117e39fcab328 to your computer and use it in GitHub Desktop.
Save Debilski/c31b9f131f51d9f38f1117e39fcab328 to your computer and use it in GitHub Desktop.
Bug in pelita noiser
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Broken noiser in pelita master"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"7dabbcc3 ENH: More default gitignores\r\n"
]
}
],
"source": [
"!git log --oneline | head -1"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pelita.datamodel import CTFUniverse\n",
"from pelita.game_master import ManhattanNoiser"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define our test layout"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"test_layout = \"\"\"\n",
" ##################\n",
" # #\n",
" # #\n",
" # 0 1 #\n",
" # #\n",
" # #\n",
" ##################\n",
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Setup the test game.\n",
"We want to know all possible positions of 0 that can be observed by bot 1."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"universe = CTFUniverse.create(test_layout, 2)\n",
"noiser = ManhattanNoiser(universe.copy(), noise_radius=2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Noise the position for a couple of times and place a food item where 1 observes 0 to be."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"for i in range(200):\n",
" new_uni = noiser.uniform_noise(universe.copy(), 1)\n",
" assert new_uni.bots[0].noisy\n",
" universe.food.add(new_uni.bots[0].current_pos)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"##################\n",
"# . #\n",
"# ... #\n",
"# ..0. 1 #\n",
"# ... #\n",
"# #\n",
"##################\n",
"Team(index=0, zone=(0, 8), score=0)\n",
"\tBot(index=0, initial_pos=(5, 3), team_index=0, homezone=(0, 8), current_pos=(5, 3), noisy=False)\n",
"Team(index=1, zone=(9, 17), score=0)\n",
"\tBot(index=1, initial_pos=(14, 3), team_index=1, homezone=(9, 17), current_pos=(14, 3), noisy=False)\n",
"\n"
]
}
],
"source": [
"print(universe.pretty)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That’s not a diamond shape …"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"test_layout = \"\"\"\n",
" ######################\n",
" # #\n",
" # #\n",
" # #\n",
" # #\n",
" # #\n",
" # 0 1 #\n",
" # #\n",
" # #\n",
" # #\n",
" # #\n",
" # #\n",
" ######################\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"universe = CTFUniverse.create(test_layout, 2)\n",
"noiser = ManhattanNoiser(universe.copy(), noise_radius=5)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"for i in range(500):\n",
" new_uni = noiser.uniform_noise(universe.copy(), 1)\n",
" assert new_uni.bots[0].noisy\n",
" universe.food.add(new_uni.bots[0].current_pos)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"######################\n",
"# . #\n",
"# ... #\n",
"# ..... #\n",
"# ....... #\n",
"#......... #\n",
"#....0.... 1 #\n",
"#......... #\n",
"# ....... #\n",
"# ..... #\n",
"# ... #\n",
"# #\n",
"######################\n",
"Team(index=0, zone=(0, 10), score=0)\n",
"\tBot(index=0, initial_pos=(5, 6), team_index=0, homezone=(0, 10), current_pos=(5, 6), noisy=False)\n",
"Team(index=1, zone=(11, 21), score=0)\n",
"\tBot(index=1, initial_pos=(18, 6), team_index=1, homezone=(11, 21), current_pos=(18, 6), noisy=False)\n",
"\n"
]
}
],
"source": [
"print(universe.pretty)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (pelita)",
"language": "python",
"name": "pelita"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment