tag:blogger.com,1999:blog-43447009900083698162023-11-25T18:11:24.205+01:00/random_dev_notes.txtrbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-4344700990008369816.post-68132080420417133772022-03-05T16:00:00.001+01:002022-03-05T17:27:00.715+01:000. StarCraft II Python Bot: Introduction<h2 style="text-align: left;"><span style="font-size: large;"># Python library for StarCraft II</span></h2><div><div>«An easy-to-use library for writing AI Bots for StarCraft II in Python 3. The ultimate goal is simplicity and ease of use, while still preserving all functionality. A really simple worker rush bot should be no more than twenty lines of code, not two hundred. However, this library intends to provide both high and low level abstractions.»</div></div><div><br /></div><div style="text-align: right;"><a href="https://github.com/Dentosal/python-sc2" target="_blank">https://github.com/Dentosal/python-sc2</a></div><div style="text-align: left;"><br /></div><div style="text-align: left;">You can find<b> how to install</b> in the <a href="https://github.com/Dentosal/python-sc2" target="">previous link</a>.</div><div><br /></div><div><h1 style="text-align: left;"># About this tutorial</h1></div><div><div>I structured this tutorial in three parts. From the beginning to the end it adds more and more things your bot can do. Every chapter will add a new functionality and when you finish your (Terran) bot, it will have a basic behaviour: gather, build an army, attack.</div><div><br /></div><div>This tutorial has two parts to get you started on programming a StarCraft II Bot using python libraries and the StarCraft II game.</div><div><br /></div><div>The structure is the next:</div><div><ul style="text-align: left;"><li> 0. This introduction</li><li> 1. Gathering resources</li><li> 2. Building units</li></ul><div><br /></div><h2 style="text-align: left;"><span style="font-size: large;"># Starcraft Race of the bot</span></h2></div></div><h4 style="text-align: left;">- Terran</h4><div>The terrans (or humans) are a young species with psionic potential. The terrans of the Koprulu sector descend from the survivors of a disastrous 23rd century colonization mission from Earth.</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhSbFWxdF3opWGyQYGr88PCxr6rVJZ4LTIZC9AAupIFtYtjvp8VWbuYzquFkog5TqgAhdvkR7ZsBiXddzgUyGkDW9a0DCl2F3CgWwD3e0DTgYnrexXZ-LxBZFOw0NMqlvtD-NmOFZ8_8zYDk8JowizdD4I6Z-f0iQVbO5fRmHadBMxAjZ-x-S9quJr-7g=s775" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="418" data-original-width="775" height="346" src="https://blogger.googleusercontent.com/img/a/AVvXsEhSbFWxdF3opWGyQYGr88PCxr6rVJZ4LTIZC9AAupIFtYtjvp8VWbuYzquFkog5TqgAhdvkR7ZsBiXddzgUyGkDW9a0DCl2F3CgWwD3e0DTgYnrexXZ-LxBZFOw0NMqlvtD-NmOFZ8_8zYDk8JowizdD4I6Z-f0iQVbO5fRmHadBMxAjZ-x-S9quJr-7g=w640-h346" width="640" /></a></div><br /><div><br /></div>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-47349860105438921002022-03-05T15:00:00.001+01:002022-03-05T17:27:08.386+01:001. StarCraft II Python Bot: Gathering resources<h2 style="text-align: left;"><span style="font-size: large;"> # <a href="https://starcraft.fandom.com/wiki/Command_center">Command Center</a></span></h2><div>The Command Center is the main building you need. On it you build your workers. You start with one the match and can expand your territory with it.</div><div><br /></div><h2 style="text-align: left;"><span style="font-size: large;"># Building the workers</span></h2><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildWorkers</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SCV) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.workers.amount < <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).amount * <span style="color: #b5cea8;">14</span> + <span style="color: #b5cea8;">4</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">commandcenter</span>.train(UnitTypeId.SCV))</div></div></div></div></div></pre></div></div><div>This is simply a function to tell the Terran Command Center to create SCVs. We need to use it in the class, so let’s put it in the class and call it in the on_sept() function. The final script of this part should look like this:</div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #c586c0;">import</span> sc2</div><div><span style="color: #c586c0;">from</span> sc2 <span style="color: #c586c0;">import</span> run_game, maps, Race, Difficulty</div><div><span style="color: #c586c0;">from</span> sc2.player <span style="color: #c586c0;">import</span> Bot, Computer</div><div><span style="color: #c586c0;">from</span> sc2.ids.unit_typeid <span style="color: #c586c0;">import</span> *</div><div> </div><div> </div><div><span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">AlanBot</span>(<span style="color: #4ec9b0;">sc2</span>.<span style="color: #4ec9b0;">BotAI</span>):</div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">on_step</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">iteration</span>):</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildWorkers</span>()</div><div> </div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildWorkers</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SCV) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.workers.amount < <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).amount * <span style="color: #b5cea8;">14</span> + <span style="color: #b5cea8;">4</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">commandcenter</span>.train(UnitTypeId.SCV))</div><div> </div><div>run_game(maps.get(<span style="color: #ce9178;">"AbyssalReefLE"</span>), [</div><div> Bot(Race.Terran, <span style="color: #4ec9b0;">AlanBot</span>()),</div><div> Computer(Race.Zerg, Difficulty.Hard)</div><div>], <span style="color: #9cdcfe;">realtime</span>=<span style="color: #569cd6;">True</span>)</div></div></div></div></div></pre></div></div><h2 style="text-align: left;"><span style="font-size: large;"># Gatering minerals</span></h2><div>The developers of this library have already implemented a function to distribute_workers(), it will gather the minerals and <a href="https://liquipedia.net/starcraft2/Refinery_(Legacy_of_the_Void)">Vespene Gas</a>, but it won’t create create the Vespene Refinery (in Terran case). We need to create the Refineries too.</div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #c586c0;">import</span> sc2</div><div><span style="color: #c586c0;">from</span> sc2 <span style="color: #c586c0;">import</span> run_game, maps, Race, Difficulty</div><div><span style="color: #c586c0;">from</span> sc2.player <span style="color: #c586c0;">import</span> Bot, Computer</div><div><span style="color: #c586c0;">from</span> sc2.ids.unit_typeid <span style="color: #c586c0;">import</span> *</div><div> </div><div> </div><div><span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">AlanBot</span>(<span style="color: #4ec9b0;">sc2</span>.<span style="color: #4ec9b0;">BotAI</span>):</div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">on_step</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">iteration</span>):</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildWorkers</span>()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.distribute_workers()</div><div> </div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildWorkers</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SCV) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.workers.amount < <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).amount * <span style="color: #b5cea8;">14</span> + <span style="color: #b5cea8;">4</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">commandcenter</span>.train(UnitTypeId.SCV))</div><div> </div><div>run_game(maps.get(<span style="color: #ce9178;">"AbyssalReefLE"</span>), [</div><div> Bot(Race.Terran, <span style="color: #4ec9b0;">AlanBot</span>()),</div><div> Computer(Race.Zerg, Difficulty.Hard)</div><div>], <span style="color: #9cdcfe;">realtime</span>=<span style="color: #569cd6;">True</span>)</div></div></div></div></div></pre></div></div><h2 style="text-align: left;"><span style="font-size: large;"># Gathering vesper gas</span></h2><div>In order to collect the vespene gas, we need <a href="https://liquipedia.net/starcraft2/Refinery_(Legacy_of_the_Void)">refineries</a> (or <a href="https://liquipedia.net/starcraft2/Extractor_(Legacy_of_the_Void)">Extractors</a> or <a href="https://liquipedia.net/starcraft2/Assimilator_(Legacy_of_the_Void)">Assimlators</a> for other Races) for the Terran SVCs.</div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildRefineries</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready:</div><div> <span style="color: #9cdcfe;">vespenes</span> = <span style="color: #9cdcfe;">self</span>.state.vespene_geyser.closer_than(<span style="color: #b5cea8;">18.0</span>, <span style="color: #9cdcfe;">commandcenter</span>)</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">vespene</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">vespenes</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #569cd6;">not</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.REFINERY):</div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #9cdcfe;">worker</span> = <span style="color: #9cdcfe;">self</span>.select_build_worker(<span style="color: #9cdcfe;">vespene</span>.position)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">worker</span> <span style="color: #569cd6;">is</span> <span style="color: #569cd6;">None</span>:</div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #c586c0;">if</span> <span style="color: #569cd6;">not</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.REFINERY).closer_than(<span style="color: #b5cea8;">1.0</span>, <span style="color: #9cdcfe;">vespene</span>).exists:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">worker</span>.build(UnitTypeId.REFINERY, <span style="color: #9cdcfe;">vespene</span>))</div></div></div></div></div></pre></div></div><div><br /></div><div>Write this as a class function of our bot and call it on the on_step() function:</div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #c586c0;">import</span> sc2</div><div><span style="color: #c586c0;">from</span> sc2 <span style="color: #c586c0;">import</span> run_game, maps, Race, Difficulty</div><div><span style="color: #c586c0;">from</span> sc2.player <span style="color: #c586c0;">import</span> Bot, Computer</div><div><span style="color: #c586c0;">from</span> sc2.ids.unit_typeid <span style="color: #c586c0;">import</span> *</div><div> </div><div> </div><div><span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">AlanBot</span>(<span style="color: #4ec9b0;">sc2</span>.<span style="color: #4ec9b0;">BotAI</span>):</div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">on_step</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">iteration</span>):</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildWorkers</span>()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.distribute_workers()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildRefineries</span>()</div><div> </div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildWorkers</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SCV) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.workers.amount < <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).amount * <span style="color: #b5cea8;">14</span> + <span style="color: #b5cea8;">4</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">commandcenter</span>.train(UnitTypeId.SCV))</div><div> </div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildRefineries</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready:</div><div> <span style="color: #9cdcfe;">vespenes</span> = <span style="color: #9cdcfe;">self</span>.state.vespene_geyser.closer_than(<span style="color: #b5cea8;">18.0</span>, <span style="color: #9cdcfe;">commandcenter</span>)</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">vespene</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">vespenes</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #569cd6;">not</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.REFINERY):</div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #9cdcfe;">worker</span> = <span style="color: #9cdcfe;">self</span>.select_build_worker(<span style="color: #9cdcfe;">vespene</span>.position)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">worker</span> <span style="color: #569cd6;">is</span> <span style="color: #569cd6;">None</span>:</div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #c586c0;">if</span> <span style="color: #569cd6;">not</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.REFINERY).closer_than(<span style="color: #b5cea8;">1.0</span>, <span style="color: #9cdcfe;">vespene</span>).exists:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">worker</span>.build(UnitTypeId.REFINERY, <span style="color: #9cdcfe;">vespene</span>))</div><div> </div><div> </div><div>run_game(maps.get(<span style="color: #ce9178;">"AbyssalReefLE"</span>), [</div><div> Bot(Race.Terran, <span style="color: #4ec9b0;">AlanBot</span>()),</div><div> Computer(Race.Zerg, Difficulty.Hard)</div><div>], <span style="color: #9cdcfe;">realtime</span>=<span style="color: #569cd6;">True</span>)</div></div></div></div></div></pre></div></div><div><br /></div><div>You should now have workers being created and gathering minerals and vespene gas for you.</div>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-5043762204195101582022-03-05T14:00:00.001+01:002022-03-05T17:27:15.079+01:002. StarCraft II Python Bot: Building units<p> You need to check different things. When<b> you want to create one Barrack</b> you <b>need</b>:</p><p></p><ul style="text-align: left;"><li><b>A location</b></li><li><b>A worker</b></li><li><b>Some requirements </b>(such as <a href="https://liquipedia.net/starcraft2/Supply_Depot_(Legacy_of_the_Void)">Supply Depots</a>)</li></ul><p></p><p>And when <b>you want to create a Marine</b> you <b>need</b>:</p><p></p><ul style="text-align: left;"><li><b>Enough minerals</b></li><li>At least <b>one Barrack</b></li><li><b>A limit of units</b> to create</li></ul><p></p><p>This is why <b>we create two different function</b>s: <i>buildStructure() </i>and<i> buildOffensiveUnit()</i>.</p><h2 style="text-align: left;"><span style="font-size: large;">- buildStructure()</span></h2><div><div>In this function we are going to receive <b>two parameters</b>: <i>the structure</i> that we want to build, and <i>the amount</i> of structures that we want of it.</div><div><br /></div><div>A good place to start building some Supply Depots and Barracks is around your first Command Center. So we are going to save the position in a variable:</div></div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #9cdcfe;">commandCenter</span> = <span style="color: #569cd6;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.random</div><div><span style="color: #9cdcfe;">nearCC</span> = <span style="color: #c586c0;">await</span> <span style="color: #569cd6;">self</span>.find_placement(UnitTypeId.SUPPLYDEPOT, commandcenter.position, <span style="color: #9cdcfe;">placement_step</span>=<span style="color: #b5cea8;">2</span>)</div></div></div></div></pre></div></div><div><div>But for the Barracks is a little more special: we need to check if there are already Supply Depots (see the Terran Tech Tree), if we have reached the limit of Barracks that we want, and if we can afford to built it.</div><div><br /></div><div>The complete function is the following:</div></div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildStructure</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">structureName</span>, <span style="color: #9cdcfe;">amount</span>):</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.exists:</div><div> <span style="color: #9cdcfe;">commandCenter</span> = <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.random</div><div> <span style="color: #9cdcfe;">workers</span> = <span style="color: #9cdcfe;">self</span>.workers.gathering</div><div> </div><div> <span style="color: #9cdcfe;">nearCC</span> = <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.find_placement(UnitTypeId.SUPPLYDEPOT, <span style="color: #9cdcfe;">commandCenter</span>.position, <span style="color: #9cdcfe;">placement_step</span>=<span style="color: #b5cea8;">2</span>)</div><div> </div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">structureName</span> == <span style="color: #ce9178;">'supplydepot'</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.supply_left < <span style="color: #b5cea8;">6</span> <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SUPPLYDEPOT):</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">workers</span>:</div><div> <span style="color: #9cdcfe;">w</span> = <span style="color: #9cdcfe;">workers</span>.furthest_to(<span style="color: #9cdcfe;">workers</span>.center)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">nearCC</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">w</span>.build(UnitTypeId.SUPPLYDEPOT, <span style="color: #9cdcfe;">nearCC</span>))</div><div> </div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">structureName</span> == <span style="color: #ce9178;">'barracks'</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units.of_type([UnitTypeId.SUPPLYDEPOT, UnitTypeId.SUPPLYDEPOTLOWERED, UnitTypeId.SUPPLYDEPOTDROP]).ready.exists</div><div> <span style="color: #569cd6;">and</span> <span style="color: #569cd6;">self</span>.units(UnitTypeId.BARRACKS).amount + <span style="color: #569cd6;">self</span>.already_pending(UnitTypeId.BARRACKS) < amount</div><div> <span style="color: #569cd6;">and</span> <span style="color: #569cd6;">self</span>.can_afford(UnitTypeId.BARRACKS):</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">workers</span>:</div><div> <span style="color: #9cdcfe;">w</span> = <span style="color: #9cdcfe;">workers</span>.furthest_to(<span style="color: #9cdcfe;">workers</span>.center)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">nearCC</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">w</span>.build(UnitTypeId.BARRACKS, <span style="color: #9cdcfe;">nearCC</span>))</div></div></div></div></pre></div><div>The nearCC variable store a location that match a free place for the Supply Depots size. You can add a second location that find a place for the size of the Barracks later.</div><div><br /></div><div><h2><span style="font-size: large;">- buildOffensiveUnit()</span></h2></div><div>The offensive unit is the way of the program to spawn our Terrans. We pass it a name, where to build it, and how many of them.</div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildOffensiveUnit</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">unitName</span>, <span style="color: #9cdcfe;">structureName</span>, <span style="color: #9cdcfe;">maxAmount</span>):</div><div><span style="color: #9cdcfe;">structure</span> = <span style="color: #9cdcfe;">self</span>.unitSelector(<span style="color: #9cdcfe;">structureName</span>)</div><div><span style="color: #9cdcfe;">unit</span> = <span style="color: #9cdcfe;">self</span>.unitSelector(<span style="color: #9cdcfe;">unitName</span>)</div><div><span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units(<span style="color: #9cdcfe;">structure</span>).ready.exists:</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">struct</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(<span style="color: #9cdcfe;">structure</span>).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(<span style="color: #9cdcfe;">unit</span>) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.supply_left > <span style="color: #b5cea8;">0</span> <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.units(<span style="color: #9cdcfe;">unit</span>).amount < <span style="color: #9cdcfe;">maxAmount</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">struct</span>.train(<span style="color: #9cdcfe;">unit</span>))</div></div></div></div></pre></div></div><h2 style="text-align: left;"><span style="font-size: large;">- Call in all in <i>on_step()</i></span></h2><div><div>For the bot to do things you need to put all your functions in the on_step() function. That way the program takes control on the synchs, and will launch everything written in the function. Maybe a good thing would be making a FSM machine, but this case is very simple.</div><div><br /></div><div>You can give it a bit of logic for some amounts of units.</div></div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div><div style="line-height: 18px;"><div><span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">on_step</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">iteration</span>):</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.buildWorkers()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.distribute_workers()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.buildRefineries()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.buildStructure(<span style="color: #ce9178;">'supplydepot'</span>, <span style="color: #b5cea8;">2000</span>)</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.buildStructure(<span style="color: #ce9178;">'barracks'</span>, <span style="color: #b5cea8;">4</span>)</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.buildOffensiveUnit(<span style="color: #ce9178;">'marine'</span>, <span style="color: #ce9178;">'barracks'</span>, <span style="color: #b5cea8;">27</span>)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.MARINE).amount > <span style="color: #b5cea8;">17</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.move(<span style="color: #ce9178;">'marine'</span>, <span style="color: #569cd6;">True</span>)</div><div> <span style="color: #c586c0;">else</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.move(<span style="color: #ce9178;">'marine'</span>, <span style="color: #569cd6;">False</span>)</div></div></div></div></pre></div></div><div><i><br /></i></div><div><i><br /></i></div>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-31475824328536460172022-02-24T12:00:00.001+01:002022-03-05T17:28:08.914+01:00Simplest terminal menu - Python<p>Here you can find a start up code for running your python project. </p><p>Import the necessary code at the beginning and modify the options in the options dictionary.</p><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div style="line-height: 18px;"><div><span style="color: #c586c0;">import</span> <span style="color: #4ec9b0;">time</span></div><br /><div><span style="color: #6a9955;"># Import here the main part of your code</span></div><div><span style="color: #c586c0;">from</span> My_script <span style="color: #c586c0;">import</span> Script</div><br /><div><span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">user_data</span>():</div><div> <span style="color: #9cdcfe;">options</span> = {</div><div> <span style="color: #b5cea8;">0</span>: <span style="color: #ce9178;">"option 0"</span>,</div><div> <span style="color: #b5cea8;">1</span>: <span style="color: #ce9178;">"option 1"</span>,</div><div> <span style="color: #b5cea8;">2</span>: <span style="color: #ce9178;">"option 2"</span></div><div> }</div><div> </div><div> <span style="color: #6a9955;"># DISPLAY MENU WITH OPTIONS</span></div><div> <span style="color: #c586c0;">while</span> <span style="color: #b5cea8;">1</span>:</div><div> <span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"</span><span style="color: #d7ba7d;">\n</span><span style="color: #ce9178;">Select and option"</span>)</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">option</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">options</span>.<span style="color: #dcdcaa;">items</span>():</div><div> <span style="color: #dcdcaa;">print</span>(<span style="color: #9cdcfe;">option</span>)</div><div> <span style="color: #9cdcfe;">selectedOption</span> = <span style="color: #dcdcaa;">input</span>(<span style="color: #ce9178;">"Option to use: "</span>)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">selectedOption</span>.<span style="color: #dcdcaa;">isdigit</span>():</div><div> <span style="color: #9cdcfe;">selectedOption</span> = <span style="color: #4ec9b0;">int</span>(<span style="color: #9cdcfe;">selectedOption</span>)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">selectedOption</span> <span style="color: #569cd6;">not</span> <span style="color: #569cd6;">in</span> <span style="color: #9cdcfe;">options</span>:</div><div> <span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"Error, not a valid option"</span>)</div><div> <span style="color: #c586c0;">else</span>: </div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #c586c0;">else</span>:</div><div> <span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"Error, choose the option digit"</span>)</div><br /><div> <span style="color: #6a9955;"># READ A FILENAME </span></div><div> <span style="color: #c586c0;">while</span> <span style="color: #b5cea8;">1</span>:</div><div> <span style="color: #9cdcfe;">file_name</span> = <span style="color: #dcdcaa;">input</span>(<span style="color: #ce9178;">"Write the file name"</span>)</div><div> <span style="color: #c586c0;">try</span>:</div><div> <span style="color: #c586c0;">with</span> <span style="color: #dcdcaa;">open</span>(<span style="color: #9cdcfe;">file_name</span>) <span style="color: #c586c0;">as</span> <span style="color: #9cdcfe;">f</span>:</div><div> <span style="color: #6a9955;"># File opened successfully</span></div><div> <span style="color: #9cdcfe;">file</span> = <span style="color: #9cdcfe;">f</span></div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #c586c0;">except</span> <span style="color: #4ec9b0;">FileNotFoundError</span>:</div><div> <span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"Error, couldn't open the file"</span>)</div><br /><div> <span style="color: #c586c0;">return</span> <span style="color: #9cdcfe;">file</span>, <span style="color: #9cdcfe;">options</span>[<span style="color: #9cdcfe;">selectedOption</span>]</div><br /><div><span style="color: #6a9955;"># Beginning of the script</span></div><div><span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"[ # PROGRAM_NAME # ]"</span>)</div><div><span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"Init program..."</span>)</div><div><span style="color: #9cdcfe;">file</span>, <span style="color: #9cdcfe;">option</span> = <span style="color: #dcdcaa;">user_data</span>()</div><div><span style="color: #9cdcfe;">start</span> = <span style="color: #4ec9b0;">time</span>.<span style="color: #dcdcaa;">time</span>()</div><div><span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"Starting the program..."</span>)</div><div>Script.main(<span style="color: #9cdcfe;">file</span>, <span style="color: #9cdcfe;">option</span>)</div></div><div><span style="color: #dcdcaa;">print</span>(<span style="color: #ce9178;">"Total time:"</span>, <span style="color: #dcdcaa;">round</span>(<span style="color: #4ec9b0;">time</span>.<span style="color: #dcdcaa;">time</span>() - <span style="color: #9cdcfe;">start</span>, <span style="color: #b5cea8;">3</span>), <span style="color: #ce9178;">"seconds."</span>) </div></div></div></pre></div><p><br /></p>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-29304419431993917902022-01-13T18:35:00.006+01:002022-01-13T19:08:51.999+01:00Unity - Oculus Quest 2 Development Setup<h4 style="text-align: left;"><span style="font-weight: normal;">We are going to </span>setup the environment<span style="font-weight: normal;"> and </span>run a Demo<span style="font-weight: normal;"> application for the </span><span style="font-weight: normal;">Oculus Quest 2 with Unity.</span></h4><div><br /></div><h2 style="text-align: left;"><span style="font-size: large;"># First Step</span></h2><p><span style="font-size: medium;">You need to <b>pair to your smartphone and enable Developer Mode</b> in the Oculus app for the smartphone. Once you have done this you can continue in your computer by installing Unity.</span></p><h2 style="text-align: left;"><span style="font-size: large;"><br /></span></h2><h2 style="text-align: left;"><span style="font-size: large;"># Unity installation</span></h2><p>First <b>install Unity Hub </b>and download Unity (a LTS version if you want)</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiH1CUbnL7YVtRI9EHzgaHhQK0Os8qZ16ufc4PwBaqBPkS67pJp7IVZKjmFTu0C_JAKyB2CJd81hdBZbmplwgHO-2r4u56NMJA7U4ytt4FNziseFCYz_u-AtYfd6vdzYiXqWBbAtFQZHqNQv7XpMjaVF9bixmv7W7Q2Tp6AOnrhsZubvnBIf-KqGd5aLA=s2272" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1424" data-original-width="2272" height="251" src="https://blogger.googleusercontent.com/img/a/AVvXsEiH1CUbnL7YVtRI9EHzgaHhQK0Os8qZ16ufc4PwBaqBPkS67pJp7IVZKjmFTu0C_JAKyB2CJd81hdBZbmplwgHO-2r4u56NMJA7U4ytt4FNziseFCYz_u-AtYfd6vdzYiXqWBbAtFQZHqNQv7XpMjaVF9bixmv7W7Q2Tp6AOnrhsZubvnBIf-KqGd5aLA=w400-h251" width="400" /></a></div><p>With the installation complete <b>create a new Unity 3D project</b>.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjtEe1Vvc-ENn2IWfEG7jOQyT8zL8Rm8F_uZnxWpTiLycO96ojuWZ6ZJIy6gF_3tGvZEbpdqfh7OKHOih8BK5StLpdp-koKQQVu3D9Z80IUmj7Xr1QbX9tsYc-UrD73XQDbG_kFZT0QKYT4AMK5hB-osFrB5kdWdZo50xVk0ja5P7kJB-oyJk1mQzJYKw=s2272" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1424" data-original-width="2272" height="251" src="https://blogger.googleusercontent.com/img/a/AVvXsEjtEe1Vvc-ENn2IWfEG7jOQyT8zL8Rm8F_uZnxWpTiLycO96ojuWZ6ZJIy6gF_3tGvZEbpdqfh7OKHOih8BK5StLpdp-koKQQVu3D9Z80IUmj7Xr1QbX9tsYc-UrD73XQDbG_kFZT0QKYT4AMK5hB-osFrB5kdWdZo50xVk0ja5P7kJB-oyJk1mQzJYKw=w400-h251" width="400" /></a></div>Now we have an empty 3D project:<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjABT5Az5Wnp-QPMq1J-51ipW8Wy_bBnmNvXId5pPh8YWrp_oE9fBavcxs9gsKhkL5D9zSY3vTGuicjiWhgv55S7pC5cPgetzoEFLWBXqhk5A8EGgl-mpOY-e32a4Li_4HT8g5aqvp3G0lhZKygfq5hBFzWZg3-9cnjoyo4zpyFc6IubNtNkv-K27dSaA=s3230" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1960" data-original-width="3230" height="243" src="https://blogger.googleusercontent.com/img/a/AVvXsEjABT5Az5Wnp-QPMq1J-51ipW8Wy_bBnmNvXId5pPh8YWrp_oE9fBavcxs9gsKhkL5D9zSY3vTGuicjiWhgv55S7pC5cPgetzoEFLWBXqhk5A8EGgl-mpOY-e32a4Li_4HT8g5aqvp3G0lhZKygfq5hBFzWZg3-9cnjoyo4zpyFc6IubNtNkv-K27dSaA=w400-h243" width="400" /></a></div>If you didn't install the needed External Tools as the JDK and SDK, you need to install them from the Unity Hub, just <i>Add Modules</i> to the Unity install, add the <b>Android SDK & NDK Tools</b>, and if you don't have it either, install the <b>Open JDK</b>.<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEj5U6cnet1Q1O3SIl2yJX4ydwj3L3060DeTdtOdLZN38uhNi4yEN-VcWNCNDKevlWPSxmw8jo9gurkWVv7cdOCVqMYcP9fq_A2cXxMUBVvu8IZfDsi0I9FGhaX4l03zxDFrcYtRyDjX9-Fy63H9-2byW2SjG_NKsILCzWaVeSlfl8IOlxQQZYieCYSwJQ=s2272" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1424" data-original-width="2272" height="251" src="https://blogger.googleusercontent.com/img/a/AVvXsEj5U6cnet1Q1O3SIl2yJX4ydwj3L3060DeTdtOdLZN38uhNi4yEN-VcWNCNDKevlWPSxmw8jo9gurkWVv7cdOCVqMYcP9fq_A2cXxMUBVvu8IZfDsi0I9FGhaX4l03zxDFrcYtRyDjX9-Fy63H9-2byW2SjG_NKsILCzWaVeSlfl8IOlxQQZYieCYSwJQ=w400-h251" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhJSVWIusFVhpyWsRAilNM6g9FtTHtR_gF4aTB3NCgSQAor7iUFuFwBo5mxd1FjlFI9AMXrmNf6kdo_lzJQ26QxhIclD0vCeHMyPrlQm4I9fyNTj3jG2RH-ihWXQun5U9cTlA2ifk846tPeD4Nat_CMgnDIUtPryRXnOOei82PjmiHLksjnG5--3jq3pQ=s1720" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1302" data-original-width="1720" height="242" src="https://blogger.googleusercontent.com/img/a/AVvXsEhJSVWIusFVhpyWsRAilNM6g9FtTHtR_gF4aTB3NCgSQAor7iUFuFwBo5mxd1FjlFI9AMXrmNf6kdo_lzJQ26QxhIclD0vCeHMyPrlQm4I9fyNTj3jG2RH-ihWXQun5U9cTlA2ifk846tPeD4Nat_CMgnDIUtPryRXnOOei82PjmiHLksjnG5--3jq3pQ=s320" width="320" /></a></div><div class="separator" style="clear: both; text-align: left;">Now if you go to the Build Settings, switch to Android and, with your Oculus Quest connected via USB to your computer, make sure that you can see the device in <b>Run Device</b>.</div><div class="separator" style="clear: both; text-align: left;">The name of the device should be something like you see here:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi5STzOWASd7EAcXtXN-iyht0DimkhJgyhq0__-tZ53PLf3Yx5vuEe_QUnmy5B_IRAoDYzkMCBQc512aa5cr51ad5aAm0xlj9jOp3ajXcYprPoI0dRGm3Wb2PHHwBX87I8OQnu5wC1DN4-mPyF6HRwmATi8fZpKj-UfxAsO5DLWmHS60_4sx98YZ5jJYA=s1736" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1482" data-original-width="1736" height="341" src="https://blogger.googleusercontent.com/img/a/AVvXsEi5STzOWASd7EAcXtXN-iyht0DimkhJgyhq0__-tZ53PLf3Yx5vuEe_QUnmy5B_IRAoDYzkMCBQc512aa5cr51ad5aAm0xlj9jOp3ajXcYprPoI0dRGm3Wb2PHHwBX87I8OQnu5wC1DN4-mPyF6HRwmATi8fZpKj-UfxAsO5DLWmHS60_4sx98YZ5jJYA=w400-h341" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><h2 style="text-align: left;"><span style="font-size: large;"># Oculus Tools</span> </h2><div class="separator" style="clear: both; text-align: left;">We need to download the tools from the Unity Asset Store, they are free. Go to the <a href="https://assetstore.unity.com" target="_blank">Asset Store</a> and add to Unity the <a href="https://assetstore.unity.com/packages/tools/integration/oculus-integration-82022" target="_blank">Oculus Integration</a>. </div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjnCcyG3KJkVZ2M0FD-1CeyfnM37dJfZtIcOhxLcKE-v8Wzq9ac5Pugu4JV3NHnOJ1Lo1iwAxPtxYvGHDL9mC_euUszMbmzmSCmMtC-l7Etm_LXa_wzHfrK_9aB7WCZDtpHejYI8QzkvZM1RFA7GkTlxwOCvIxiK3Hqe6hZlwHPsawqqsUVeU6Yl57MRw=s2814" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="2178" data-original-width="2814" height="248" src="https://blogger.googleusercontent.com/img/a/AVvXsEjnCcyG3KJkVZ2M0FD-1CeyfnM37dJfZtIcOhxLcKE-v8Wzq9ac5Pugu4JV3NHnOJ1Lo1iwAxPtxYvGHDL9mC_euUszMbmzmSCmMtC-l7Etm_LXa_wzHfrK_9aB7WCZDtpHejYI8QzkvZM1RFA7GkTlxwOCvIxiK3Hqe6hZlwHPsawqqsUVeU6Yl57MRw=s320" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: left;">In the Unity Package Manager, add the Oculus Integration by downloading and Import everything to your project.</div></div><div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhg0tzs1lS6nJ8mQuQGksCvVf5JWrDQV7Cpbl8EKKdSF3ulLuyhZLJeG0d8qKulPnxX8tVtJtFrZW73Qrc57XYdntUXpXFbNfstGL3vsJwYxf2jAYD8yPpTAy5Qtm9WRxGU7fsl4Bo0nHDkL9egdz9lPWrVjd8AOtENOhgQGvY0JyGbIxRr8NM0680qRQ=s1824" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1426" data-original-width="1824" height="250" src="https://blogger.googleusercontent.com/img/a/AVvXsEhg0tzs1lS6nJ8mQuQGksCvVf5JWrDQV7Cpbl8EKKdSF3ulLuyhZLJeG0d8qKulPnxX8tVtJtFrZW73Qrc57XYdntUXpXFbNfstGL3vsJwYxf2jAYD8yPpTAy5Qtm9WRxGU7fsl4Bo0nHDkL9egdz9lPWrVjd8AOtENOhgQGvY0JyGbIxRr8NM0680qRQ=s320" width="320" /></a></div><div style="text-align: left;"><span style="font-size: large;"><br /></span></div><h2 style="text-align: left;"><span style="font-size: large;"># Unity Setup</span></h2><div>There are some changes that we need to do in the Unity settings to get the games and the demos to work properly in the Oculus, such as use OpenGLES3 and the installation of the XR Plug-in.</div><div><br /></div><h3 style="text-align: left;">- Using OpenGLES3</h3>In order to Build and Run for the Oculus Quest 2 we need to change the Graphic API, we need to put the <b>OpenGLES3 before Vulkan</b> in the Project Settings/Player/Other Settings:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiK6o-L61TbABFSxaIDEC6TE444b7b5d-tN6HNH3vuBZ-qrrMUEgeuOoOPezegXJuj5wHe-3WxoJGIISXg0EIrg9JR-3vlRMhnaAscsKQS5Val_0lNjr-nGw_F0OXB-T8gqS6T5oKbGF0ko_vInnrLD1WZO393wx4-Zxs8iFd29Kf0fCJuyjMadNQwgjg=s1748" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1226" data-original-width="1748" height="224" src="https://blogger.googleusercontent.com/img/a/AVvXsEiK6o-L61TbABFSxaIDEC6TE444b7b5d-tN6HNH3vuBZ-qrrMUEgeuOoOPezegXJuj5wHe-3WxoJGIISXg0EIrg9JR-3vlRMhnaAscsKQS5Val_0lNjr-nGw_F0OXB-T8gqS6T5oKbGF0ko_vInnrLD1WZO393wx4-Zxs8iFd29Kf0fCJuyjMadNQwgjg=s320" width="320" /></a></div><h3 style="text-align: left;">- Install XR Plug-in</h3><div>Make sure that you have <b>XR Plug-in</b> installed for the Oculus. In the project Settings go to XR Plug-in Manager and install it. Then in the Android tab, check the Oculus:</div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjaPfhQwZ92dzMYiO2iMqE6mkokZdWvC_5eCGTl2CIAwlj6skFBeYKNCVwwQlPV1RXzaAS3PkhLfy-P9IzoYxGWJOwpZtMJpC49tMY5zeGJIuq6z_6P0cgbKA-2BSxV52ZUa8EVV79-ueaj4NSlYuPRXK9VpHQerQkBwsaSKaA8XP2Lsx1yqIEll5V7SA=s1748" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1226" data-original-width="1748" height="224" src="https://blogger.googleusercontent.com/img/a/AVvXsEjaPfhQwZ92dzMYiO2iMqE6mkokZdWvC_5eCGTl2CIAwlj6skFBeYKNCVwwQlPV1RXzaAS3PkhLfy-P9IzoYxGWJOwpZtMJpC49tMY5zeGJIuq6z_6P0cgbKA-2BSxV52ZUa8EVV79-ueaj4NSlYuPRXK9VpHQerQkBwsaSKaA8XP2Lsx1yqIEll5V7SA=s320" width="320" /></a></div><div style="text-align: left;"><span style="font-size: large;"><br /></span></div><h2 style="text-align: left;"><span style="font-size: large;"># Testing the Demo Files</span></h2><h3><div style="font-weight: normal;">You can find some Demos in the files that we imported. Look under the Assets/Oculus/SampleFramework/Usage, there you can find the Demo files such as DistanceGrab:</div><div class="separator" style="clear: both; font-weight: normal; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjj1_SXEERYMTpwj8bDDX418AQOd3BGN9KFYLUjmWYxb51hUlP8QA0VKbnkDrgPiZQGxIWjKfh3xwlWsta4izYziizJFrs95kSjpvibk4ffVhcd6LVqx_7tIJSPoAbPpy3sWGpF_4k9X2PFvLrBySAlECyBFZCUu_pd0bbipeD9yp3xM7Oj4-ygPM3mgw=s3596" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="2362" data-original-width="3596" height="263" src="https://blogger.googleusercontent.com/img/a/AVvXsEjj1_SXEERYMTpwj8bDDX418AQOd3BGN9KFYLUjmWYxb51hUlP8QA0VKbnkDrgPiZQGxIWjKfh3xwlWsta4izYziizJFrs95kSjpvibk4ffVhcd6LVqx_7tIJSPoAbPpy3sWGpF_4k9X2PFvLrBySAlECyBFZCUu_pd0bbipeD9yp3xM7Oj4-ygPM3mgw=w400-h263" width="400" /></a></div></h3><h3 style="text-align: left;">- Run the demo</h3>Now you can <b>add the scene to the <i>Scenes in Build</i> in the Build Settings</b> and <b>click Build and Run</b>, and make sure to allow your computer to write on the Oculus. Put the glasses on and accept the dialogs. Then the compilation should be starting and when it finishes you can see the demo in your Oculus.<br /><div> </div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiMQNK594dK4qcCJtQVXMLVZg4g-jXz61mBQFdTEqyK4TVrI9e-eAoyfPDWmSkExwS9YSZug4dogM2PsRGhHBuOiVa-GDjfqBgtG68HDgbSJJkFLwiwsKkTv3-hMyaIOkpe-eMOyf9-RXiJ9LivsF2R1bMWul69miPgBClqg_cpSJ8rA2Slnxx9heCeig=s2160" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="2160" height="200" src="https://blogger.googleusercontent.com/img/a/AVvXsEiMQNK594dK4qcCJtQVXMLVZg4g-jXz61mBQFdTEqyK4TVrI9e-eAoyfPDWmSkExwS9YSZug4dogM2PsRGhHBuOiVa-GDjfqBgtG68HDgbSJJkFLwiwsKkTv3-hMyaIOkpe-eMOyf9-RXiJ9LivsF2R1bMWul69miPgBClqg_cpSJ8rA2Slnxx9heCeig=w400-h200" width="400" /></a></div><br /><br /><h4 style="text-align: left;"><span style="font-size: medium;">And that's it! We have a running game <b>created and compiled with Unity</b> in the Oculus Quest 2.</span></h4>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-82455510287014789482022-01-07T19:00:00.003+01:002022-01-07T19:25:48.623+01:00Blender - Procedural Sand Shader - with Download<p>Quick sand material / shader to add to your project, with a NodeGroup to make it easy to change the parameters. Download at the bottom of the post.</p><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhOL95E0j3UrC1b16Tp6G070nZwt48bxsFt-WPfOhpx0DL90uDwNKPTm_gvrbpXZcY7dDDgs0mDKs5Z_rSwzJY1ui0b7jg8nJ3neKshl-l7AlsRJcxi9AIN5Z9t8jJCFARNDuGrQ3XHLp8Zj0a5QNGD4cBf2Doyo65wPnNgs5q2D4GwhsbclaKocf7OnA=s1106" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="938" data-original-width="1106" height="271" src="https://blogger.googleusercontent.com/img/a/AVvXsEhOL95E0j3UrC1b16Tp6G070nZwt48bxsFt-WPfOhpx0DL90uDwNKPTm_gvrbpXZcY7dDDgs0mDKs5Z_rSwzJY1ui0b7jg8nJ3neKshl-l7AlsRJcxi9AIN5Z9t8jJCFARNDuGrQ3XHLp8Zj0a5QNGD4cBf2Doyo65wPnNgs5q2D4GwhsbclaKocf7OnA=s320" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEh5sMg0dyZA2R9IMb0mjBDpNNvpFR1uyfOC3Lnkif5P1UtOZgHm7gTktdCACRMhpcCS32bK0fIfdQ8aolDg_2aQXDrsvaQqirwkawCoTfb1AFq1ER_zgb-gw833Qc9JTAedyU0-uWihfjHIEv3-ByztfszQcwWdrijTh2tWzm8128ndVlwcBdTdZt7KFQ=s3014" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1484" data-original-width="3014" height="316" src="https://blogger.googleusercontent.com/img/a/AVvXsEh5sMg0dyZA2R9IMb0mjBDpNNvpFR1uyfOC3Lnkif5P1UtOZgHm7gTktdCACRMhpcCS32bK0fIfdQ8aolDg_2aQXDrsvaQqirwkawCoTfb1AFq1ER_zgb-gw833Qc9JTAedyU0-uWihfjHIEv3-ByztfszQcwWdrijTh2tWzm8128ndVlwcBdTdZt7KFQ=w640-h316" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgm3U7Ip8S1vdrP0jSMXtw8P6xJMdIm14jOS_hDeH7BpzY-veWSGzJrNXuAVYzm9l4-7y3pZMJqHF_931AYrXkJxNQOOOmEC4vp07aX0iQdG-4_Q_2mEWbJlrfkudp572n9sEmYc_Tr-rhn-GXy24y8QhIyl3XH4nGE8JuumegQ63PSj6wb9BQWOEKbrg=s1920" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1920" height="225" src="https://blogger.googleusercontent.com/img/a/AVvXsEgm3U7Ip8S1vdrP0jSMXtw8P6xJMdIm14jOS_hDeH7BpzY-veWSGzJrNXuAVYzm9l4-7y3pZMJqHF_931AYrXkJxNQOOOmEC4vp07aX0iQdG-4_Q_2mEWbJlrfkudp572n9sEmYc_Tr-rhn-GXy24y8QhIyl3XH4nGE8JuumegQ63PSj6wb9BQWOEKbrg=w400-h225" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEib-HrkisO7A_Fqs1G2epXoMIYHS6TcwOiNeFj4mYNhD3jsbeObtBNlao2FKQRX4wIs5xPgEFpxwZxemC9QXnL4H7SnU4dcGMZw0-ltLlX9JeF4oZ_2Tu4Puk1RhGYN05uWli_Kqpq5k02WwRKXhD0x5px-sfBQtU9lPGbMGmUxYN2CpjEkIVat_K59oQ=s1920" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1920" height="225" src="https://blogger.googleusercontent.com/img/a/AVvXsEib-HrkisO7A_Fqs1G2epXoMIYHS6TcwOiNeFj4mYNhD3jsbeObtBNlao2FKQRX4wIs5xPgEFpxwZxemC9QXnL4H7SnU4dcGMZw0-ltLlX9JeF4oZ_2Tu4Puk1RhGYN05uWli_Kqpq5k02WwRKXhD0x5px-sfBQtU9lPGbMGmUxYN2CpjEkIVat_K59oQ=w400-h225" width="400" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEh6G5Kqvgu6A6H-iabjKRvaV9nB7Y4_OcsrxNgd0zrgoSvGpjccSzDDl1YfnXsLEok6kbN7CTISMOSasbOzHWuhzr_Xjy5QWuaCVODatbqBwHGinxvW6coONw6Q7H_7B-wqNWPTj7evjZl1_LParZrHENvp7Oq6Ahd3H6_vq--o5n50pjDRBf64BjTJVA=s1920" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1920" height="225" src="https://blogger.googleusercontent.com/img/a/AVvXsEh6G5Kqvgu6A6H-iabjKRvaV9nB7Y4_OcsrxNgd0zrgoSvGpjccSzDDl1YfnXsLEok6kbN7CTISMOSasbOzHWuhzr_Xjy5QWuaCVODatbqBwHGinxvW6coONw6Q7H_7B-wqNWPTj7evjZl1_LParZrHENvp7Oq6Ahd3H6_vq--o5n50pjDRBf64BjTJVA=w400-h225" width="400" /></a></div><br /><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgyzAKxGNay0TPE3MBFxmg_6iSxV1fBeI2XyyEGZdmuL13MRD5XsUKYmJ8xr8yqm02trhAKXDUIlvnk0CJoz7whSjlUZEx20nqqSZ9kpXAH75erZuRBIfl56GS0jSM2buuTGEWsUb7uzA7S4F19yaq0OGfquN2bO4c62NWbNG4XWtJG8374yTnvQ-2SdQ=s1920" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1920" height="360" src="https://blogger.googleusercontent.com/img/a/AVvXsEgyzAKxGNay0TPE3MBFxmg_6iSxV1fBeI2XyyEGZdmuL13MRD5XsUKYmJ8xr8yqm02trhAKXDUIlvnk0CJoz7whSjlUZEx20nqqSZ9kpXAH75erZuRBIfl56GS0jSM2buuTGEWsUb7uzA7S4F19yaq0OGfquN2bO4c62NWbNG4XWtJG8374yTnvQ-2SdQ=w640-h360" width="640" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEixS6IEL7GUWZTKTuUo1m6D7msaSbg-OlN_Z2v02Yk2qy92rpLIoo4-HUkQCRXWieflaHvjh4I0f5cTvkLPGCtw3Vnh2w5EhKucNA74dLuUaBPfKHqN0n_T-yyKFvS1ylAnalLz__epoM_ITO-DHmdrSvXKlQ_KEcWn8uT_2pZ9uDvW2o0_lObQtJbbdQ=s1920" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1920" height="360" src="https://blogger.googleusercontent.com/img/a/AVvXsEixS6IEL7GUWZTKTuUo1m6D7msaSbg-OlN_Z2v02Yk2qy92rpLIoo4-HUkQCRXWieflaHvjh4I0f5cTvkLPGCtw3Vnh2w5EhKucNA74dLuUaBPfKHqN0n_T-yyKFvS1ylAnalLz__epoM_ITO-DHmdrSvXKlQ_KEcWn8uT_2pZ9uDvW2o0_lObQtJbbdQ=w640-h360" width="640" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://mega.nz/file/6cBFXILT#I2sl693QvOU5nVvXtvUQVBy_a49-LxYPQuFjmlFpnZY" target="_blank"><span style="font-size: large;">DOWNLOAD</span></a></div><br /><div><br /></div>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-88674520765684682922021-12-23T18:04:00.009+01:002022-01-07T14:43:26.085+01:00Use Three.js inside Ruby on Rails<h4 style="text-align: left;"><span style="font-size: medium; font-weight: normal;">This example uses the online resources of <i>three.js</i>, we don't have to download any <i>three.js </i>packages.</span></h4><div><br /></div><div><br /></div><div><br /></div><h2 style="text-align: left;"><span style="font-size: x-large;"># Create the Rails webpage</span></h2><div><br /></div><div>We are going to start with the normal Ruby on Rails new project <b>in a terminal</b>:</div><div><h4><ul style="text-align: left;"><li><span style="font-weight: normal;">$ rails new app</span></li><li><span style="font-weight: normal;">$ cd app</span></li></ul><div><span style="font-weight: normal;">Test if the app is running by:</span></div><div><ul style="text-align: left;"><li><span style="font-weight: normal;">$ rails s</span></li><li><span style="font-weight: normal;">Go to <a href="http://localhost:3000/" target="_blank">http://localhost:3000/</a></span></li></ul><div><span style="font-weight: normal;">If you see a welcome page saying "<i>Yay! You're on Rails!"</i> everything went correctly.</span></div></div><div><span style="font-weight: normal;"><br /></span></div><div><span style="font-weight: normal;"><br /></span></div></h4><h2><span style="font-size: x-large;"># Create a home page</span></h2></div><div><br /></div><div>By creating a new controller we can set it as the home page for this project:</div><div><br /></div><div><ul style="text-align: left;"><li>$ rails g controller home index</li></ul><div><br /></div><div>Now we have home controller with an action called index, which will be the home page once we setup the routes. Right now the only way of accessing the new view of this controller is going to <a href="http://localhost:3000/home/index" target="_blank">http://localhost:3000/home/index</a>. But with a new route we can <b>set this as the landing page</b>.</div></div><div><br /></div><div>Go to the routes file in <i>app/config/routes.rb</i>, then write a new line to indicate the new route:</div><div><br /></div><div><ul style="text-align: left;"><li>root 'home#index' </li></ul><div><br /></div>And delete the other route. Then the <i>routers.rb </i>should be looking like this:</div><div><br /></div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div><span style="color: #4ec9b0;">Rails</span>.<span style="color: #dcdcaa;">application</span>.<span style="color: #dcdcaa;">routes</span>.<span style="color: #dcdcaa;">draw</span> <span style="color: #c586c0;">do</span></div><div> <span style="color: #9cdcfe;">root</span> <span style="color: #ce9178;">'home#index'</span></div><div><span style="color: #c586c0;">end</span></div></div></pre></div><div><br /></div><div>The homepage is set. You can go to <a href="http://localhost:3000/">http://localhost:3000/</a> and find the home page as the landing page.</div><div><br /></div><div><br /></div><div><br /></div><div><h2><span style="font-size: x-large;"># Put a <i>three.js</i> canvas in the home page</span></h2></div><div><br /></div><div>In order to use <i>three.js</i> inside the page we can use a partial to have everything organised in our project. By doing a partial we can have a separate file to write our <i>three.js</i> code.</div><div><br /></div><div><h2><span style="font-size: large;">Create a partial</span></h2></div><div><br /></div><div>Go to the <i>app/views/home</i> folder and create a new file called:</div><div><br /></div><div><ul style="text-align: left;"><li>_3d_viewer.html.erb</li></ul><div><br /></div></div><div>Is very important to use the '_' in the beginning of the name of a partial.</div><div><br /></div><div>Now we can use this partial to write our <i>three.js</i> code. We just need to reference the library and use it with two <i>script</i> tag</div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div><span style="color: grey;"><</span><span style="color: #569cd6;">script</span> <span style="color: #9cdcfe;">src</span>=<span style="color: #ce9178;">"https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"</span><span style="color: grey;">></</span><span style="color: #569cd6;">script</span><span style="color: grey;">></span></div><br /><div><span style="color: grey;"><</span><span style="color: #569cd6;">script</span><span style="color: grey;">></span></div><div> <!-- <span style="color: #9cdcfe;">three</span>.<span style="color: #9cdcfe;">js</span> <span style="color: #9cdcfe;">code</span> <span style="color: #9cdcfe;">goes</span> <span style="color: #9cdcfe;">here</span> --></div><div><span style="color: grey;"></</span><span style="color: #569cd6;">script</span><span style="color: grey;">></span> </div></div></div></pre></div><div><br /></div><div>With the source as <a href="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js" target="_blank">https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js</a> we can use the <i>three.js </i>library.</div><div><br /></div><div><h2><span style="font-size: large;">Show the partial in home page</span></h2></div><div><br /></div><div>The only thing left to do is to show the <i>three.js</i> in the home page. Just write one more line in the view for the homepage:</div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div style="line-height: 18px;"><div><span style="color: grey;"><</span><span style="color: #569cd6;">h1</span><span style="color: grey;">></span>Home#index<span style="color: grey;"></</span><span style="color: #569cd6;">h1</span><span style="color: grey;">></span></div><div><span style="color: grey;"><</span><span style="color: #569cd6;">p</span><span style="color: grey;">></span>Find me in app/views/home/index.html.erb<span style="color: grey;"></</span><span style="color: #569cd6;">p</span><span style="color: grey;">></span></div><br /></div><div><span style="color: #569cd6;"><%=</span> <span style="color: #9cdcfe;">render</span> <span style="color: #569cd6;">partial:</span> <span style="color: #ce9178;">"3d_viewer"</span> <span style="color: #569cd6;">%></span> </div></div></div></pre></div><div><br /></div><div><br /></div><div><h2><span style="font-size: x-large;"># View the results</span></h2></div><div><br /></div><div>With an initial code for <i>three.js</i> to work we can see the results in the homepage:</div><div><br /></div><div style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEiISKJ54dCTOTpLfwHBvj7fsL-dzHfDo505ghxPLAZ1C49jYcC-D74JdRCaeucIW4j0rGDwqd4U8VaBzudwGYSY94uBEIujuOYkv4NO4DW7khI623UPSXs91O6-2gf-0JwqMq8xMI9sB0CIlUiz36ZtBeEB2xeBr76gfNwJsyYqcKxyMiVXi7cbeQpCQQ=s2152"><img border="0" data-original-height="1448" data-original-width="2152" height="430" src="https://blogger.googleusercontent.com/img/a/AVvXsEiISKJ54dCTOTpLfwHBvj7fsL-dzHfDo505ghxPLAZ1C49jYcC-D74JdRCaeucIW4j0rGDwqd4U8VaBzudwGYSY94uBEIujuOYkv4NO4DW7khI623UPSXs91O6-2gf-0JwqMq8xMI9sB0CIlUiz36ZtBeEB2xeBr76gfNwJsyYqcKxyMiVXi7cbeQpCQQ=w640-h430" width="640" /></a></div><br /><div style="text-align: center;"><br /></div><div><h2><span style="font-size: large;"><i><br /></i></span></h2><h2><span style="font-size: large;"><i>Three.js </i>code of the example</span></h2></div><div><br /></div><div>In the <i>_3d_viewer.html.erb</i></div><div><div><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div style="line-height: 18px;"><div style="line-height: 18px;"><div style="line-height: 18px;"><div><span style="color: grey;"><</span><span style="color: #569cd6;">script</span> <span style="color: #9cdcfe;">src</span>=<span style="color: #ce9178;">"https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"</span><span style="color: grey;">></</span><span style="color: #569cd6;">script</span><span style="color: grey;">></span></div><br /><div><span style="color: grey;"><</span><span style="color: #569cd6;">script</span><span style="color: grey;">></span></div><div> <span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">scene</span> = <span style="color: #569cd6;">new</span> <span style="color: #4fc1ff;">THREE</span>.<span style="color: #dcdcaa;">Scene</span>();</div><div> <span style="color: #569cd6;">const</span> <span style="color: #4fc1ff;">WIDTH</span> = <span style="color: #b5cea8;">500</span>;</div><div> <span style="color: #569cd6;">const</span> <span style="color: #4fc1ff;">HEIGHT</span> = <span style="color: #b5cea8;">500;</span></div><div> <span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">camera</span> = <span style="color: #569cd6;">new</span> <span style="color: #4fc1ff;">THREE</span>.<span style="color: #dcdcaa;">PerspectiveCamera</span>( <span style="color: #b5cea8;">75</span>, <span style="color: #4fc1ff;">WIDTH</span>/<span style="color: #4fc1ff;">HEIGHT</span>, <span style="color: #b5cea8;">0.1</span>, <span style="color: #b5cea8;">1000</span> );</div><div><span style="color: #9cdcfe;">camera</span>.<span style="color: #9cdcfe;">position</span>.<span style="color: #9cdcfe;">z</span> = <span style="color: #b5cea8;">4</span>;</div><div> <span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">renderer</span> = <span style="color: #569cd6;">new</span> <span style="color: #4fc1ff;">THREE</span>.<span style="color: #dcdcaa;">WebGLRenderer</span>({<span style="color: #9cdcfe;">antialias:</span><span style="color: #569cd6;">true</span>});</div><br /><div> <span style="color: #9cdcfe;">renderer</span>.<span style="color: #dcdcaa;">setClearColor</span>(<span style="color: #ce9178;">"#000000"</span>);</div><div> <span style="color: #9cdcfe;">renderer</span>.<span style="color: #dcdcaa;">setSize</span>( <span style="color: #b5cea8;">400</span>, <span style="color: #b5cea8;">400</span> );</div><div> <span style="color: #9cdcfe;">document</span>.<span style="color: #9cdcfe;">body</span>.<span style="color: #dcdcaa;">appendChild</span>( <span style="color: #9cdcfe;">renderer</span>.<span style="color: #9cdcfe;">domElement</span> );</div><br /><div> <span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">geometry</span> = <span style="color: #569cd6;">new</span> <span style="color: #4fc1ff;">THREE</span>.<span style="color: #dcdcaa;">BoxGeometry</span>( <span style="color: #b5cea8;">1</span>, <span style="color: #b5cea8;">1</span>, <span style="color: #b5cea8;">1</span> );</div><div> <span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">material</span> = <span style="color: #569cd6;">new</span> <span style="color: #4fc1ff;">THREE</span>.<span style="color: #dcdcaa;">MeshBasicMaterial</span>( { <span style="color: #9cdcfe;">color:</span> <span style="color: #ce9178;">"#433F81"</span> } );</div><div> <span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">cube</span> = <span style="color: #569cd6;">new</span> <span style="color: #4fc1ff;">THREE</span>.<span style="color: #dcdcaa;">Mesh</span>( <span style="color: #9cdcfe;">geometry</span>, <span style="color: #9cdcfe;">material</span> );</div><br /><div> <span style="color: #9cdcfe;">scene</span>.<span style="color: #dcdcaa;">add</span>( <span style="color: #9cdcfe;">cube</span> );</div><br /><div> <span style="color: #569cd6;">var</span> <span style="color: #dcdcaa;">render</span> = <span style="color: #569cd6;">function</span> () {</div><div> <span style="color: #dcdcaa;">requestAnimationFrame</span>( <span style="color: #9cdcfe;">render</span> );</div><br /><div> <span style="color: #9cdcfe;">cube</span>.<span style="color: #9cdcfe;">rotation</span>.<span style="color: #9cdcfe;">y</span> += <span style="color: #b5cea8;">0.01</span>;</div><br /><div> <span style="color: #9cdcfe;">renderer</span>.<span style="color: #dcdcaa;">render</span>(<span style="color: #9cdcfe;">scene</span>, <span style="color: #9cdcfe;">camera</span>);</div><div> };</div><br /><div> <span style="color: #dcdcaa;">render</span>();</div><div><span style="color: grey;"></</span><span style="color: #569cd6;">script</span><span style="color: grey;">></span></div></div></div></div></div></pre></div><div><br /></div></div><div><br /></div>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-50151882181175017312021-11-30T18:31:00.003+01:002022-04-20T16:47:44.214+02:00Terran Bot for StarCraft II - Python<p><span style="color: white;">Find the explanation in <a href="https://xcran.blogspot.com/2022/03/0-starcraft-ii-python-bot-introduction.html">https://xcran.blogspot.com/2022/03/0-starcraft-ii-python-bot-introduction.html</a></span></p><pre style="background-color: black; background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><span style="color: white;"><div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px;"><div><span style="color: #c586c0;">import</span> sc2</div><div><span style="color: #c586c0;">from</span> sc2 <span style="color: #c586c0;">import</span> run_game, maps, Race, Difficulty</div><div><span style="color: #c586c0;">from</span> sc2.player <span style="color: #c586c0;">import</span> Bot, Computer</div><div><span style="color: #c586c0;">from</span> sc2.ids.unit_typeid <span style="color: #c586c0;">import</span> *</div><br /><br /><div><span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">AlanBot</span>(<span style="color: #4ec9b0;">sc2</span>.<span style="color: #4ec9b0;">BotAI</span>):</div><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">on_step</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">iteration</span>):</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildWorkers</span>()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.distribute_workers()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildRefineries</span>()</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildStructure</span>(<span style="color: #ce9178;">'supplydepot'</span>, <span style="color: #b5cea8;">2000</span>)</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildStructure</span>(<span style="color: #ce9178;">'barracks'</span>, <span style="color: #b5cea8;">4</span>)</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.<span style="color: #dcdcaa;">buildOffensiveUnit</span>(<span style="color: #ce9178;">'marine'</span>, <span style="color: #ce9178;">'barracks'</span>, <span style="color: #b5cea8;">27</span>)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.MARINE).amount > <span style="color: #b5cea8;">17</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.move(<span style="color: #ce9178;">'marine'</span>, <span style="color: #569cd6;">True</span>)</div><div> <span style="color: #c586c0;">else</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.move(<span style="color: #ce9178;">'marine'</span>, <span style="color: #569cd6;">False</span>)</div><br /><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildWorkers</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SCV) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.workers.amount < <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).amount * <span style="color: #b5cea8;">14</span> + <span style="color: #b5cea8;">4</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">commandcenter</span>.train(UnitTypeId.SCV))</div><br /><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildRefineries</span>(<span style="color: #9cdcfe;">self</span>):</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">commandcenter</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready:</div><div> <span style="color: #9cdcfe;">vespenes</span> = <span style="color: #9cdcfe;">self</span>.state.vespene_geyser.closer_than(</div><div> <span style="color: #b5cea8;">18.0</span>, <span style="color: #9cdcfe;">commandcenter</span>)</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">vespene</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">vespenes</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #569cd6;">not</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.REFINERY):</div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #9cdcfe;">worker</span> = <span style="color: #9cdcfe;">self</span>.select_build_worker(<span style="color: #9cdcfe;">vespene</span>.position)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">worker</span> <span style="color: #569cd6;">is</span> <span style="color: #569cd6;">None</span>:</div><div> <span style="color: #c586c0;">break</span></div><div> <span style="color: #c586c0;">if</span> <span style="color: #569cd6;">not</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.REFINERY).closer_than(<span style="color: #b5cea8;">1.0</span>, <span style="color: #9cdcfe;">vespene</span>).exists:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">worker</span>.build(UnitTypeId.REFINERY, <span style="color: #9cdcfe;">vespene</span>))</div><br /><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildStructure</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">structureName</span>, <span style="color: #9cdcfe;">amount</span>):</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.exists:</div><div> <span style="color: #9cdcfe;">commandCenter</span> = <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.COMMANDCENTER).ready.random</div><div> <span style="color: #9cdcfe;">workers</span> = <span style="color: #9cdcfe;">self</span>.workers.gathering</div><br /><div> <span style="color: #9cdcfe;">nearCC</span> = <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.find_placement(UnitTypeId.SUPPLYDEPOT, <span style="color: #9cdcfe;">commandCenter</span>.position, <span style="color: #9cdcfe;">placement_step</span>=<span style="color: #b5cea8;">2</span>)</div><br /><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">structureName</span> == <span style="color: #ce9178;">'supplydepot'</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.supply_left < <span style="color: #b5cea8;">6</span> <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.SUPPLYDEPOT):</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">workers</span>:</div><div> <span style="color: #9cdcfe;">w</span> = <span style="color: #9cdcfe;">workers</span>.furthest_to(<span style="color: #9cdcfe;">workers</span>.center)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">nearCC</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">w</span>.build(UnitTypeId.SUPPLYDEPOT, <span style="color: #9cdcfe;">nearCC</span>))</div><br /><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">structureName</span> == <span style="color: #ce9178;">'barracks'</span>:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units.of_type([UnitTypeId.SUPPLYDEPOT, UnitTypeId.SUPPLYDEPOTLOWERED, UnitTypeId.SUPPLYDEPOTDROP]).ready.exists \</div><div> <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.units(UnitTypeId.BARRACKS).amount + <span style="color: #9cdcfe;">self</span>.already_pending(UnitTypeId.BARRACKS) < <span style="color: #9cdcfe;">amount</span> \</div><div> <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.can_afford(UnitTypeId.BARRACKS):</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">workers</span>:</div><div> <span style="color: #9cdcfe;">w</span> = <span style="color: #9cdcfe;">workers</span>.furthest_to(<span style="color: #9cdcfe;">workers</span>.center)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">nearCC</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">w</span>.build(UnitTypeId.BARRACKS, <span style="color: #9cdcfe;">nearCC</span>))</div><br /><div> <span style="color: #569cd6;">async</span> <span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">buildOffensiveUnit</span>(<span style="color: #9cdcfe;">self</span>, <span style="color: #9cdcfe;">unitName</span>, <span style="color: #9cdcfe;">structureName</span>, <span style="color: #9cdcfe;">maxAmount</span>):</div><div> <span style="color: #9cdcfe;">structure</span> = <span style="color: #9cdcfe;">self</span>.unitSelector(<span style="color: #9cdcfe;">structureName</span>)</div><div> <span style="color: #9cdcfe;">unit</span> = <span style="color: #9cdcfe;">self</span>.unitSelector(<span style="color: #9cdcfe;">unitName</span>)</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.units(<span style="color: #9cdcfe;">structure</span>).ready.exists:</div><div> <span style="color: #c586c0;">for</span> <span style="color: #9cdcfe;">struct</span> <span style="color: #c586c0;">in</span> <span style="color: #9cdcfe;">self</span>.units(<span style="color: #9cdcfe;">structure</span>).ready.noqueue:</div><div> <span style="color: #c586c0;">if</span> <span style="color: #9cdcfe;">self</span>.can_afford(<span style="color: #9cdcfe;">unit</span>) <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.supply_left > <span style="color: #b5cea8;">0</span> <span style="color: #569cd6;">and</span> <span style="color: #9cdcfe;">self</span>.units(<span style="color: #9cdcfe;">unit</span>).amount < <span style="color: #9cdcfe;">maxAmount</span>:</div><div> <span style="color: #c586c0;">await</span> <span style="color: #9cdcfe;">self</span>.do(<span style="color: #9cdcfe;">struct</span>.train(<span style="color: #9cdcfe;">unit</span>))</div><br /><br /><div>run_game(maps.get(<span style="color: #ce9178;">"AbyssalReefLE"</span>), [</div><div> Bot(Race.Terran, <span style="color: #4ec9b0;">AlanBot</span>()),</div><div> Computer(Race.Zerg, Difficulty.Medium)</div><div>], <span style="color: #9cdcfe;">realtime</span>=<span style="color: #569cd6;">True</span>)</div></div></span></pre><div><span style="color: white;"><br /></span></div><div><span style="color: white;"><span style="font-size: 12px;"><br /></span></span></div>rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-63131904692485361012021-11-24T20:22:00.003+01:002021-12-23T18:27:52.571+01:00Detener actividad de disco duro HDD desde terminal - GNU/Linux<div style="text-align: justify;">
Para detener la actividad del HDD de nuestro ordenador podemos hacer uso del comando <i>hdparm</i>, se usa <b>como ejemplo el disco duro principal</b> <i>/dev/sda</i>, probablemente quiera detener otro disco duro<i>. </i></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><br /></div><div style="text-align: justify;"><span style="font-size: medium;">Modo Sleep:</span></div>
<ul>
<li style="text-align: justify;"><span style="font-size: medium;">$ <b>sudo hdparm -Y /dev/sda</b></span></li></ul><div style="text-align: justify;"><span style="font-size: medium;">Modo StandBy:</span></div>
<div>
<ul>
<li style="text-align: justify;"><span style="font-size: medium;">$ <b>sudo hdparm -y /dev/sda</b></span></li></ul><div style="text-align: justify;"><b><br /></b></div></div><div style="text-align: justify;"><b><br /></b></div>
rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-85581960128169874362021-05-28T19:42:00.001+02:002021-12-23T16:48:24.298+01:00Instalar .run en Ubuntu [GNU/Linux] desde terminal<div style="text-align: justify;"><ol><li><span style="font-size: medium;">Desde el terminal acceda a la carpeta con los comandos <i>cd </i>y <i>cd ..</i></span></li><li><span style="font-size: medium;">Dar permisos de ejecución:</span></li><ul><li><span style="font-size: medium;">$ <b>sudo chmod +x archivo.run</b></span></li></ul><li><span style="font-size: medium;">Ejecutar el archivo:</span></li><ul><li><span style="font-size: medium;">$<b> ./archivo.run</b></span></li></ul></ol></div>
rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-90996450399446504132018-12-20T15:51:00.001+01:002018-12-20T15:55:51.450+01:00C Funtioncs - Count chars, words and lines<pre style="background: rgb(0, 0, 0); border: 1px dashed rgb(221, 221, 221); height: auto; line-height: 20px; overflow: auto; padding: 0px; width: 646.469px;"><span style="color: white;"><span style="font-size: 12px;">#include <stdio.h>
#define IN 1
#define OUT 0
int main(){
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while((c = getchar()) != EOF){
++nc;</span> /*Count chars*/<span style="font-size: 12px;">
if(c == '\n') ++nl;</span> /*Count lines*/<span style="font-size: 12px;">
if(c == ' ' || c == '\n' || c == '\t') state = OUT;
else if(state == OUT){
state = IN;
++nw;</span> /*Count words*/<span style="font-size: 12px;">
}
}
printf("[Lines: %d]\n[Words: %d]\n[Chars: %d]\n", nl, nw, nc);
return 0;
}</span></span></pre>
<br />rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.comtag:blogger.com,1999:blog-4344700990008369816.post-86543388427513068332018-12-14T14:10:00.001+01:002018-12-14T14:10:18.120+01:00C Functions - Multiplication Example<pre style="background: #000000; border: 1px dashed #dddddd; color: black; font-family: "arial"; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: white; word-wrap: normal;">#include <stdio.h><stdio .h="">
int multNumbers(int a, int b);
int main(){
int number1 = 3;
int number2 = 4;
int mult;
mult = multNumbers(number1, number2);
printf("mult = %d",mult);
return 0;
}
int multNumbers(int a,int b){
return result a * b;
}</stdio></code></pre>
rbgrhttp://www.blogger.com/profile/08346428079311209161noreply@blogger.com