A higher resolution is required to access the IDE
- 15
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Defeat the Boss to advance to the next league and compete against the best bots!
The Goal
Rules
Definitions
- The game is played on a rectangular field.
- Players alternate and each turn plant one of their flowers in the field.
- When
4 or more flowers of the same type are planted in a line (vertical, horizontal or diagonal), they are harvested and the player earns gold.
- Have more gold than your opponent at the end of the game.
- Output an invalid command or don't respond in time.
- Run out of gold.
- Have less gold than your opponent at the end of the game.
Expert Rules
Details
- After harvest, grass is found on the tiles.
- The field has fieldHeight rows and fieldWidth columns.
- The top-left corner has position (0,0).
- col goes to the right, row increases downwards.
- Each turn you specify where you want to plant your flower by giving row and col.
Planting costs
It is allowed to plant your flower anywhere within the field. However, there is a cost associated with planting, which depends on the state of the tile, you want to plant in.
The cost is deducted from your gold stockpile before planting the flower. You lose, if you do not have enough gold.
Planting on soil is free, on grass it costs
Harvesting flowers
The flowers are harvested according to the following algorithm.
for each direction (horizontal, vertical, both diagonals)
- count the number of adjacent flowers starting from the flower just planted in both ways
- if the number of adjacent flowers in this direction is larger or equal to
4 , all adjacent flowers in this direction are harvested.
Earning gold
- The gold earned from N harvested flowers is calculated by summing the first N numbers in the Fibonacci sequence.
- Example: when harvesting
4 flowers, the player earns 1+1+2+3=7 gold, when harvesting6 flowers, player earns 1+1+2+3+5+8=20 gold.
Examples
Here is an example where the Tulip player plants a tulip on grass and then harvests 4 flowers and earns 1+1+2+3=7 gold. He first pays the fee for planting on grass (1 gold) and only then earns gold from harvesting, thus turning a profit of 6 gold.
Here is an example where the Daisy player harvests 5 flowers and earns 1+1+2+3+5=12 gold.
Finally, here is an example where the Daisy player harvests 7 flowers in 2 directions and earns 1+1+2+3+5+8+13=33 gold.
Game Input
Line 1: two integers fieldWidth and fieldHeight
Line 2: four integers costSoil, costGrass, costRocks, costFlower
Line 3: two strings yourFlowers and opponentsFlowers
During each turn:Line 1: an integer turnsLeft
Line 2: two integers yourGold and opponentGold
fieldHeight lines: a string gridLine of length fieldWidth representing the tiles encoded by
8 ≤ fieldHeight ≤ 16
You start the game with
Initially,
There are
Response time first turn ≤
Response time per turn ≤
Tulips & Daisies
A higher resolution is required to access the IDE