1 <div class="statement-body">
3 <div class="statement-section statement-goal">
5 <span class="icon icon-goal"> </span>
8 <div class="statement-goal-content">
9 Don't get destroyed by the troll.
13 <div class="statement-section statement-rules">
15 <span class="icon icon-rules"> </span>
18 <div class="statement-rules-content">
19 If you have stones, shoot <const>1</const> or more of them.
21 If you don't have stones, shoot <const>0</const> exactly.
24 <div class="statement-section statement-warning">
26 <span class="icon icon-warning"> </span>
27 <span>Rule Evolution</span>
29 <div class="statement-warning-content">
31 The game isn't finished, but I'm not taking any more
32 suggestions at this time, the path is now determined. There
33 will be three leagues:
37 single small map, cheating is tolerated, boss plays tit for
38 tat (9/10) or cheats (1/10)
41 rock troll and ice troll unlocked; multiple rounds;
42 four maps available; no cheating; boss plays well but
46 all races unlocked; map continuum, no boss but default
48 <!-- I've actually got plans on a generic way to do
49 that. It's going to need many many hacks and a
50 viewer module. It's not planned for too soon. -->
54 For the WIP phase of this draft, I'll likely merge the last
55 two leagues into one because we need data on what makes the
59 You're still welcome to discuss the game
60 <a href="https://forum.codingame.com/t/troll-vs-castles-brainstorm/184827?u=jbm">
64 <a href="https://www.codingame.com/contribute/view/507070b7925f661e2d2835c14f950b9d157e">
65 on the contribution's page.
70 <div class="statement-victory-conditions">
71 <div class="icon victory"></div>
73 <div class="title">Victory Condition</div>
74 <div class="text">Your opponent loses.</div>
77 <div class="statement-lose-conditions">
78 <div class="icon lose"></div>
80 <div class="title">Defeat Condition</div>
82 <li>The troll reaches your castle.</li>
83 <li>When no player has stones left, the troll is closer to your castle.</li>
87 <div class="statement-section statement-protocol">
89 <span class="icon icon-protocol"> </span>
90 <span>I/O Protocol</span>
92 <div class="statement-protocol-content">
93 <p style="margin-bottom: 1em">
94 This place used to read: “Just read the sample code. You can
95 figure this out.” Here are the formalities for <em>that
96 other</em> part of the audience.
99 <div class="title">Map Input</div>
102 Your first line of input contains five space-separated
105 <dl style="margin: 1em;">
106 <dt><var>roadLength</var></dt>
107 <dd style="margin-left: 6em;">
108 distance between both castles, between <const>6</const>
109 and <const>14</const>.
111 <dt><var>initialStones</var></dt>
112 <dd style="margin-left: 6em;">
113 number of stones a castle starts the day with,
114 between <const>0</const> and <const>50</const>.
116 <dt><var>gameSeed</var></dt>
117 <dd style="margin-left: 6em;">
118 the game's seed. The game AIs use it to provide you
119 with reproducible matches even when they use stochastic
120 algorithms, and you're encouraged to do the same! See
121 examples section below for simple ways to achieve that.
123 <dt><var>gameSide</var></dt>
124 <dd style="margin-left: 6em;">
125 which side you're on, as <const>-1</const>
126 or <const>1</const>. It's not supposed to make a
127 difference to how you handle the rest of the game, but
128 you can XOR it to your <code>gameSeed</code> to have a
129 (reproducible) random that doesn't necessarily draw
130 when it plays against itself.
132 <dt><var>reserved</var></dt>
133 <dd style="margin-left: 6em;">
134 reserved for future use, ignore for now.
140 <div class="title">Turn Input</div>
143 At each turn, you are provided with the following three
144 space-separated values:
146 <dl style="margin: 1em;">
147 <dt><var>trollDistance</var></dt>
148 <dd style="margin-left: 6em;">
149 distance between the troll and your castle
151 <dt><var>stones</var></dt>
152 <dd style="margin-left: 6em;">
153 number of stones you have left
155 <dt><var>opponentStones</var></dt>
156 <dd style="margin-left: 6em;">
157 number of stones your opponent has left
163 <div class="title">Turn Output</div>
166 After having received your turn input, you are to output
167 a single integer <var>stones</var>: the number of stones
168 you wish to throw at the troll.
170 <p style="margin-top: 1ex">
171 You may optionally provide a <em>message</em> you wish
172 your castle to yell at the troll or at your opponent.
173 Just append it to your output, being sure to separate it
174 with at least one space.
175 <!-- It has no incidence on the game whatsoever. Unless
176 you're god, that is. -->
181 <div class="title">Timing Considerations</div>
184 You're allowed the default SDK timings. I think it's one
185 second for the first turn and 50 ms then, but don't
192 <div class="statement-section statement-examples">
194 <span class="icon icon-example"> </span>
195 <span>Proper RNG seeding examples</span>
198 table.jbm-statement th { border-bottom: 2px dashed #f2bb13 }
199 table.jbm-statement td { border-bottom: 1px dashed #f2bb13 }
201 <table class="jbm-statement">
203 <th>Language Family</th>
209 long mySecretSalt = 0x4242424242424242L;<br>
210 Random random = new Random(gameSeed ^ gameSide ^ mySecretSalt);
214 <td>C, C++, Perl…</td>
216 srand(gameSeed ^ gameSide ^ 0xdeadb33f);<br>
217 std::srand(gameSeed ^ gameSide ^ 12345);<br>
218 srand( $gameSeed ^ $gameSide ^ 0xCAFE_BABE );
223 <td>Unachievable until proven otherwise</td>
227 <div class="statement-section statement-expertrules">
229 <span class="icon icon-expertrules"> </span>
230 <span>Expert rules</span>
232 <div class="statement-expert-rules-content">
234 In the lower leagues, the following maps are available and
235 randomly yet extremely fairly (you wouldn't believe the
236 effort that went into this) chosen uniformly at random among
249 <table class="jbm-statement" id="jbm-maps" style="margin: 1ex">
255 <td><const>6</const></td>
256 <td><const>15</const></td>
259 <td><const>6</const></td>
260 <td><const>30</const></td>
263 <td><const>14</const></td>
264 <td><const>30</const></td>
267 <td><const>14</const></td>
268 <td><const>50</const></td>
272 You may also override them via game
273 settings <var>roadLength</var> and <var>initialStones</var>,
274 so long as you remember you won't be choosing them for
279 <div class="statement-section statement-protocol">
281 <span class="icon icon-protocol"> </span>
282 <span>Change Log</span>
285 I'm not maintaining the full changelog here anymore as the
286 <a href="https://troll.desast.re/troll.git">game's source
287 repository</a> is now publicly available. I'll just make note
288 of the single latest change, so you can know how far behind you
289 were lagging. Patches welcome, BTW.
292 This draft's last change is:
294 not taking any more suggestions.
298 <div class="statement-story-background">
299 <div class="statement-story"
300 style="position: relative; min-height: min-content">
301 <div class="story-text">
302 <div style="text-align: center">
303 “Trolls simply detest the very sight of dwarves (uncooked).”
305 <div style="text-align: right">
306 — J.R.R. Tolkien, <i>The Hobbit</i>
309 <div class="story-text" style="margin-top: 4em">
311 Based on an involuntary suggestion by
312 <span class="card" cg-codingamer-card-popup=""
313 userid="user.codingamer.userId">
315 href="/profile/dbfa96e0ac9b77a3db679628f27224ae8509333"
316 title="Zaap38">Zaap38</a>
318 on the #Fr channel. The original appears to be by
319 <a href="http://andre.lovichi.free.fr/teaching/ea/2015-2016/cours/troll/Trolls_et_chateaux.pdf">
320 Romain André-Lovichi