{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "IKogHoj_hqy4"
},
"source": [
"# PyData DropBlox coding competition ๐งฑ\n",
"This Notebook shows you how to generate submissions. The real optimization work is up to you! โ๐ป \n",
"\n",
"> Hosted by [GoDataDriven](https://godatadriven.com/) for PyConDE & PyData Berlin 2022."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Challenge and Rules ๐\n",
"\n",
"The task is simple: given a rectangular field and a set of predefined blocks, fill the field with the blocks in a way to maximize your score.\n",
"\n",
"How do you score high? That depends on the colors of the blocks you used, the rows you filled and the amount of empty tiles in the final field. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### > Field\n",
"\n",
"You are given a `Field` object `field` with `field.height = field.width = 100`. Initially it is empty, but you can drop blocks in the field which will change the array `field.values`. To make it visual, simply print your field and view the result in a text editor.\n",
"\n",
"### > Blocks\n",
"\n",
"Blocks have a shape, a color and a unique ID. They are defined as instances of the class `Block`. The list of available blocks is defined as `blocks` in the provided notebook. Similar as with the field, we can visualize the blocks. The first block, `B = blocks[0]` with `B.block_id = 0`, looks like this:\n",
"```\n",
"๐ง๐ง๐ง\n",
"๐งโฌ๏ธ๐ง\n",
"โฌ๏ธโฌ๏ธ๐ง\n",
"```\n",
"This is an orange block, so `B.color = \"O\"`, and it has `B.width = B.height = 3`. \n",
"\n",
"Blocks can be dropped into the field from top to bottom, and they stop falling until they hit another block or the bottom of the field. Blocks are dropped in the field *as is*, so they cannot be rotated. Also, a block can only be dropped once, but you don't have to use all of the provided blocks. \n",
"\n",
"Okay, now we can drop this block in our field, but how do we decide where to drop it?\n",
"\n",
"### > Rewards\n",
"\n",
"Each color has a number of *points* and a *multiplication factor*. These will determine your score, once you dropped some of blocks in the field. The values for each color are defined under `rewards`. For example, for orange, we have `rewards.points[\"O\"] = 5` and `rewards.multiplication_factors[\"O\"] = \n",
"3`. \n",
"\n",
"This means: for every orange tile in our final field, we get +5 points. So just by dropping the orange block from above we would already get +30 points. \n",
"\n",
"With the multiplication factor, things can get crazy: if the *entire row* is filled with tiles of the * same color*, you get the values of those tiles multiplied by the corresponding factor. \n",
"\n",
"Lastly, you can get minus points. If a row contains at least one colored tile, all empty tiles in that row count as -1 towards your final score.\n",
"\n",
"That should help you decide which blocks to drop, and where!\n",
"\n",
"\n",
"## Your Solution ๐ป\n",
"\n",
"Your solution should be a `.txt` file where each line specifies which block (by block ID) to drop in the field, and at which x-coordinate. To clarify, the *bottom left* of the block will be dropped at the provided x-coordinate in the field.\n",
"\n",
"For exmple, you could write `solution.txt` with:\n",
"```\n",
"322 54\n",
"12 4\n",
"...\n",
"```\n",
"which tells us to first drop the block with `block_id = 322` at x-coordinate `54`, and then drop the block with `block_id = 12` at x-coordinate `4`, etc.\n",
"\n",
"Submit your solution `.txt` at: https://dropblox.azurewebsites.net/submit.\n",
"\n",
"> Note: loading the website may take a moment - it sleeps when not used. If loading fails, please try again.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rewards scheme\n",
"The rewards are like follows:\n",
"\n",
"| Emoji | Color code | Points | Multiplication factor full row |\n",
"|-------|------------|--------|-----------------------|\n",
"| ๐ฆ | \"B\" | 100 | 0 |\n",
"| ๐จ | \"Y\" | 1 | 3 |\n",
"| ๐ฉ | \"G\" | 3 | 1 |\n",
"| ๐ช | \"P\" | 5 | 2 |\n",
"| ๐ง | \"O\" | 5 | 3 |\n",
"| ๐ฅ | \"R\" | 8 | 4 |\n",
"\n",
"
\n",
"Good luck! ๐ช๐ป"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "I193GlrrPshR"
},
"source": [
"## Let's start!\n",
"Import definitions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "5nljvNsQM-S7"
},
"outputs": [],
"source": [
"from typing import List\n",
"\n",
"# Data types\n",
"from common.data_models import (\n",
" Field,\n",
" Block,\n",
" Rewards,\n",
" Solution\n",
")\n",
"\n",
"# Puzzle helper functions\n",
"from common.parsing import (\n",
" parse_puzzle,\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "yJyvNoBPOpY-"
},
"source": [
"Read puzzle specification file"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "ZAimvAxqhrBy"
},
"outputs": [],
"source": [
"field: Field\n",
"blocks: List[Block]\n",
"rewards: Rewards\n",
"field, blocks, rewards = parse_puzzle(\n",
" \"./puzzle.txt\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "d4gp3zhKPXaK"
},
"source": [
"## Example submission"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CNWt46l4M5Yp"
},
"source": [
"Check out the first block"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tSPKZgB3M3-H",
"outputId": "18d7daf0-a1ac-46b3-8517-0ce51e5ff481"
},
"outputs": [],
"source": [
"first_block = blocks[0]\n",
"first_block"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "TZbqsPNQM1UT"
},
"source": [
"Drop it somewhere"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2f_a4iRNN22F"
},
"outputs": [],
"source": [
"x = 0\n",
"field.drop_block(first_block, x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The order of dropped blocks and their corresponding positions are stored.\n",
"These are used to create your solutions file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"field.block_ids, field.block_positions"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "bJ9XuS4BOLX8"
},
"source": [
"Check out the field"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Csf_Vs6RODGL",
"outputId": "501e1dca-626f-4e31-c75b-4bcf4b0d0174"
},
"outputs": [],
"source": [
"field"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Show our score ๐"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"field.score_solution(rewards)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "UPZHZj6aPyAS"
},
"source": [
"## Writing the solution file"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "iVlTISFZON1q"
},
"source": [
"Write our solution to disk ๐พ"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "Wis3JpFNMrl5"
},
"outputs": [],
"source": [
"field.write_solution(\"solution.txt\")"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "zEl-rw9yQ10E"
},
"source": [
"Submit your solution ๐ ! Upload at:\n",
"\n",
"[https://dropblox.azurewebsites.net/submit](https://dropblox.azurewebsites.net/submit)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## About\n",
"> Competition hosted by [GoDataDriven](https://godatadriven.com/) for PyConDE & PyData Berlin 2022."
]
}
],
"metadata": {
"colab": {
"name": "PyData DropBlox coding competition",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.9.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}