diff --git a/_config.yml b/_config.yml
index 1f2484b1b3..fda910c15d 100644
--- a/_config.yml
+++ b/_config.yml
@@ -30,18 +30,17 @@
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
-title: Your awesome title
-subtitle: Your awesome subtitle
+title: Hi, it's Teo
+subtitle: Come learn with me!
description: >- # this means to ignore newlines until "baseurl:"
- This is the demo site for a Jekyll theme version of
- HTML5 UP's sleek, responsive site template Prologue.
-author: Your Incredible Name
-email: your-email@example.com
+ Documenting my journey of self-learning CS
+author: Teo Petrea
+email: teodora.petrea@gmail.com
avatar: assets/images/avatar.jpg
# You'll want to customize url and baseurl for your own site:
-baseurl: "/jekyll-theme-prologue" # the subpath of your site, e.g. /blog
-url: "" # the base hostname & protocol for your site
+# baseurl: "/jekyll-theme-prologue" # the subpath of your site, e.g. /blog
+url: "https://teopufulete.github.io" # the base hostname & protocol for your site
# Social settings
# Make sure to include the full url including protocol, e.g. https://github.com/chrisbobbe
@@ -49,8 +48,9 @@ twitter_url:
facebook_url:
googleplus_url:
instagram_url:
-linkedin_url:
-github_url:
+youtube_url: https://www.youtube.com/channel/UC1BkKl-KwRgdQWXPYG-KKDA?view_as=subscriber
+linkedin_url: https://www.linkedin.com/in/teodora-petrea-444617193/
+github_url: https://github.com/teopufulete
stackoverflow_url:
pinterest_url:
slack_url:
@@ -59,6 +59,9 @@ dribbble_url:
# Google Analytics Tracking ID goes here:
google_analytics:
+
+
+highlighter: rouge
# The following settings are NECESSARY for the Prologue theme to run:
-theme: jekyll-theme-prologue
+remote_theme: chrisbobbe/jekyll-theme-prologue
collections: [sections]
diff --git a/_includes/social_icons.html b/_includes/social_icons.html
index a4b4ed75ba..1433002e08 100644
--- a/_includes/social_icons.html
+++ b/_includes/social_icons.html
@@ -3,6 +3,9 @@
{%- if site.twitter_url -%}
{%- endif -%}
diff --git a/_layouts/blog.html b/_layouts/blog.html
index e8f90d7d83..e8dd93400a 100644
--- a/_layouts/blog.html
+++ b/_layouts/blog.html
@@ -21,5 +21,6 @@
{%- capture _link -%}read more{%- endcapture -%}
{%- assign _content = _excerpt | append: _link -%}
{%- include section.html title=_title subtitle=_subtitle content=_content -%}
+
{%- endfor -%}
-
\ No newline at end of file
+
diff --git a/_posts/2012-09-12-first-post.md b/_posts/2012-09-12-first-post.md
deleted file mode 100644
index 98a1c51994..0000000000
--- a/_posts/2012-09-12-first-post.md
+++ /dev/null
@@ -1,14 +0,0 @@
----
-title: First Post
-author: Chris
-layout: post
----
-Lorem ipsum dolor sit amet, iusto ridens dictas te sed. Error latine vis et. Ex cum munere definitiones, ne quas debitis contentiones cum, epicurei constituam ea sit. Dicant aeterno dolorum ex eum, qui everti iisque consectetuer ea! Duo in falli similique, nec tritani accusam te. Enim sapientem intellegat te pri, nam at atqui accumsan vituperata.
-
-Sed id graeci feugiat. No meis summo consequat vel! Albucius phaedrum omittantur eos an, ex sit lorem possim perpetua. Usu et sumo posidonium, ut qui dicat sapientem tincidunt, et has consul oporteat torquatos! In qui fabulas facilisis, justo nonumes an his, quo vidisse nusquam facilisis no. Eam iriure mediocrem suavitate an?
-
-Quo te solum malorum prompta, porro oblique senserit cum et! Pro wisi cetero periculis ei, nam ullum dicit accusam ne, ad quo apeirian principes dissentiunt. An mea mucius vocent iisque? Vel eu altera consetetur, clita perfecto mea ad. Eos in vero ullum regione, ei veniam disputando pro, nam et iuvaret detracto voluptua.
-
-Ad tritani deleniti sit, ne per ubique habemus singulis. Pro at integre alienum mediocritatem, mea ad libris adipisci necessitatibus, nostro constituam sit te. Recusabo oportere et mea, case minimum deleniti no quo, deseruisse conclusionemque vis te. Nam ex iudicabit constituam accommodare, dicam singulis ex eos! Eu mea viderer ceteros repudiandae, id erat voluptatum mea, ut consul omittam convenire quo. Id justo ipsum mei, modus contentiones per et! At mel omnium lucilius instructior, vel quando graeco in, eos docendi periculis eloquentiam ut.
-
-Eam habemus aliquando ut. Id idque virtute antiopam duo, et idque falli incorrupte eos, in sea omnium instructior. Mei ex nostrud moderatius cotidieque, cu sea partiendo euripidis, eam no tollit doming! Has ne facilisi vulputate, aliquando disputationi mel eu. Ex pri diceret delectus intellegam, regione definiebas pro ex.
\ No newline at end of file
diff --git a/_posts/2013-09-12-second-post.md b/_posts/2013-09-12-second-post.md
deleted file mode 100644
index ac533f87b1..0000000000
--- a/_posts/2013-09-12-second-post.md
+++ /dev/null
@@ -1,72 +0,0 @@
----
-title: Second Post
-author: Chris
-layout: post
----
-
-Lorem ipsum dolor sit amet, harum malorum nominavi mea et. Atqui maluisset duo cu, summo dignissim voluptatum sit ut. Ad quo quidam delicatissimi. Cum nihil noster patrioque id. Per at maiorum definitiones. Cu vix sint aliquip. No duo alia sale persecuti.
-
-Pri id consul meliore luptatum, vix iudico impetus salutatus eu, duo at causae admodum complectitur. Qui eu salutandi dignissim, ea dictas audire commodo eos, vim cu autem dicam. Novum placerat moderatius sea ex, debet labitur reprehendunt mei ad. Tempor theophrastus et est, id tollit ponderum usu, at vis consul detraxit. Sit ut adhuc aeque.
-
-Ut eum labore antiopam. Cum eu modus rationibus. Illud deleniti cum cu. At vix illum vitae tation, solet oporteat complectitur at vel. Vim te simul eleifend, et per insolens conceptam, ad sint posidonium est. Ad vocent propriae principes duo.
-
-
-
-Audire periculis id vis, cum eu sonet option patrioque, his dicam sanctus imperdiet ad. Ad sonet dolorum est. Eu dolore adipisci volutpat mei, eu nec nisl molestiae. Usu ad veri omnesque pertinacia, duis scripserit ad nam. Quo id eligendi legendos.
-
-Eos cu partiendo vituperatoribus. Mel id duis delenit atomorum, mei tamquam nostrum ne, id eum hinc decore mediocrem. Mei feugiat habemus tincidunt ut, atqui detraxit ex usu. Vix ad commodo eripuit alienum, an has idque delicatissimi. Dolores reformidans mel ne, duis numquam disputando quo te.
-
-Eum eu tritani accusata qualisque, pro ei purto vocent. Vim in insolens hendrerit similique. Nobis munere antiopam ei vix. Cum no labore partiendo conceptam. Sea id vide viderer mandamus, magna posidonium nam at. Ad populo persius duo, vel audire detracto scribentur ut.
-
-Vim te fastidii sententiae. Vix ad facilis gloriatur, mei an diceret iracundia vituperatoribus. Iudico consetetur dissentiunt pri ut. Consul dictas pri ne. Nec an alia volumus scaevola, eos movet deleniti argumentum te. Latine abhorreant his ad, ut modus in the following table:
-
-
-
-
-
-
Name
-
Description
-
Price
-
-
-
-
-
Item 1
-
Ante turpis integer aliquet porttitor.
-
29.99
-
-
-
Item 2
-
Vis ac commodo adipiscing arcu aliquet.
-
19.99
-
-
-
Item 3
-
Morbi faucibus arcu accumsan lorem.
-
29.99
-
-
-
Item 4
-
Vitae integer tempus condimentum.
-
19.99
-
-
-
Item 5
-
Ante turpis integer aliquet porttitor.
-
29.99
-
-
-
-
-
-
100.00
-
-
-
-
-
-Amet illum at sea, est autem fabulas eu, quod nonumes lobortis no sed. Has ei fugit adipisci reprimique. Enim tamquam ornatus pri ei. Alii harum invidunt nec ex, pri vidit latine ne. Has vocent nominati rationibus ad, ex partiendo prodesset moderatius has, vim quod paulo ad. Ex nec etiam electram, pri illud appetere eu.
-
-An nobis instructior eos, eam libris aperiam corrumpit ex. Case omnesque eu per. Et vix iisque tritani. Autem posidonium eu vis, sit et mutat brute. Usu ne postulant intellegat omittantur, mazim saperet adolescens mel at.
-
-Nam at velit percipit detraxit, quas modus mea ut. Ius an natum doctus vivendum. Quo at debet vidisse viderer, mollis eripuit ex nec. Sed ut choro saepe, sale augue sea et. His nemore dolorum mnesarchum at, ius an adipisci aliquando, laoreet placerat ea ius.
\ No newline at end of file
diff --git a/_posts/2014-09-12-third-post.md b/_posts/2014-09-12-third-post.md
deleted file mode 100644
index 75e4e0e8ca..0000000000
--- a/_posts/2014-09-12-third-post.md
+++ /dev/null
@@ -1,30 +0,0 @@
----
-title: Third Post
-author: Chris
-layout: post
-icon: fa-lightbulb
-icon-style: regular
----
-See the icon?
-
-Lorem ipsum dolor sit amet, harum malorum nominavi mea et. Atqui maluisset duo cu, summo dignissim voluptatum sit ut. Ad quo quidam delicatissimi. Cum nihil noster patrioque id. Per at maiorum definitiones. Cu vix sint aliquip. No duo alia sale persecuti.
-
-
-
-Pri id consul meliore luptatum, vix iudico impetus salutatus eu, duo at causae admodum complectitur. Qui eu salutandi dignissim, ea dictas audire commodo eos, vim cu autem dicam. Novum placerat moderatius sea ex, debet labitur reprehendunt mei ad. Tempor theophrastus et est, id tollit ponderum usu, at vis consul detraxit. Sit ut adhuc aeque.
-
-Ut eum labore antiopam. Cum eu modus rationibus. Illud deleniti cum cu. At vix illum vitae tation, solet oporteat complectitur at vel. Vim te simul eleifend, et per insolens conceptam, ad sint posidonium est. Ad vocent propriae principes duo.
-
-Audire periculis id vis, cum eu sonet option patrioque, his dicam sanctus imperdiet ad. Ad sonet dolorum est. Eu dolore adipisci volutpat mei, eu nec nisl molestiae. Usu ad veri omnesque pertinacia, duis scripserit ad nam. Quo id eligendi legendos.
-
-Eos cu partiendo vituperatoribus. Mel id duis delenit atomorum, mei tamquam nostrum ne, id eum hinc decore mediocrem. Mei feugiat habemus tincidunt ut, atqui detraxit ex usu. Vix ad commodo eripuit alienum, an has idque delicatissimi. Dolores reformidans mel ne, duis numquam disputando quo te.
-
-Eum eu tritani accusata qualisque, pro ei purto vocent. Vim in insolens hendrerit similique. Nobis munere antiopam ei vix. Cum no labore partiendo conceptam. Sea id vide viderer mandamus, magna posidonium nam at. Ad populo persius duo, vel audire detracto scribentur ut.
-
-Vim te fastidii sententiae. Vix ad facilis gloriatur, mei an diceret iracundia vituperatoribus. Iudico consetetur dissentiunt pri ut. Consul dictas pri ne. Nec an alia volumus scaevola, eos movet deleniti argumentum te. Latine abhorreant his ad, ut modus tempor euismod pri.
-
-Amet illum at sea, est autem fabulas eu, quod nonumes lobortis no sed. Has ei fugit adipisci reprimique. Enim tamquam ornatus pri ei. Alii harum invidunt nec ex, pri vidit latine ne. Has vocent nominati rationibus ad, ex partiendo prodesset moderatius has, vim quod paulo ad. Ex nec etiam electram, pri illud appetere eu.
-
-An nobis instructior eos, eam libris aperiam corrumpit ex. Case omnesque eu per. Et vix iisque tritani. Autem posidonium eu vis, sit et mutat brute. Usu ne postulant intellegat omittantur, mazim saperet adolescens mel at.
-
-Nam at velit percipit detraxit, quas modus mea ut. Ius an natum doctus vivendum. Quo at debet vidisse viderer, mollis eripuit ex nec. Sed ut choro saepe, sale augue sea et. His nemore dolorum mnesarchum at, ius an adipisci aliquando, laoreet placerat ea ius.
\ No newline at end of file
diff --git a/_posts/2015-09-12-fourth-post.md b/_posts/2015-09-12-fourth-post.md
deleted file mode 100644
index fc4f06976c..0000000000
--- a/_posts/2015-09-12-fourth-post.md
+++ /dev/null
@@ -1,24 +0,0 @@
----
-title: Fourth Post
-author: Chris
-layout: post
----
-Lorem ipsum dolor sit amet, harum malorum nominavi mea et. Atqui maluisset duo cu, summo dignissim voluptatum sit ut. Ad quo quidam delicatissimi. Cum nihil noster patrioque id. Per at maiorum definitiones. Cu vix sint aliquip. No duo alia sale persecuti.
-
-Pri id consul meliore luptatum, vix iudico impetus salutatus eu, duo at causae admodum complectitur. Qui eu salutandi dignissim, ea dictas audire commodo eos, vim cu autem dicam. Novum placerat moderatius sea ex, debet labitur reprehendunt mei ad. Tempor theophrastus et est, id tollit ponderum usu, at vis consul detraxit. Sit ut adhuc aeque.
-
-Ut eum labore antiopam. Cum eu modus rationibus. Illud deleniti cum cu. At vix illum vitae tation, solet oporteat complectitur at vel. Vim te simul eleifend, et per insolens conceptam, ad sint posidonium est. Ad vocent propriae principes duo.
-
-Audire periculis id vis, cum eu sonet option patrioque, his dicam sanctus imperdiet ad. Ad sonet dolorum est. Eu dolore adipisci volutpat mei, eu nec nisl molestiae. Usu ad veri omnesque pertinacia, duis scripserit ad nam. Quo id eligendi legendos.
-
-Eos cu partiendo vituperatoribus. Mel id duis delenit atomorum, mei tamquam nostrum ne, id eum hinc decore mediocrem. Mei feugiat habemus tincidunt ut, atqui detraxit ex usu. Vix ad commodo eripuit alienum, an has idque delicatissimi. Dolores reformidans mel ne, duis numquam disputando quo te.
-
-Eum eu tritani accusata qualisque, pro ei purto vocent. Vim in insolens hendrerit similique. Nobis munere antiopam ei vix. Cum no labore partiendo conceptam. Sea id vide viderer mandamus, magna posidonium nam at. Ad populo persius duo, vel audire detracto scribentur ut.
-
-Vim te fastidii sententiae. Vix ad facilis gloriatur, mei an diceret iracundia vituperatoribus. Iudico consetetur dissentiunt pri ut. Consul dictas pri ne. Nec an alia volumus scaevola, eos movet deleniti argumentum te. Latine abhorreant his ad, ut modus tempor euismod pri.
-
-Amet illum at sea, est autem fabulas eu, quod nonumes lobortis no sed. Has ei fugit adipisci reprimique. Enim tamquam ornatus pri ei. Alii harum invidunt nec ex, pri vidit latine ne. Has vocent nominati rationibus ad, ex partiendo prodesset moderatius has, vim quod paulo ad. Ex nec etiam electram, pri illud appetere eu.
-
-An nobis instructior eos, eam libris aperiam corrumpit ex. Case omnesque eu per. Et vix iisque tritani. Autem posidonium eu vis, sit et mutat brute. Usu ne postulant intellegat omittantur, mazim saperet adolescens mel at.
-
-Nam at velit percipit detraxit, quas modus mea ut. Ius an natum doctus vivendum. Quo at debet vidisse viderer, mollis eripuit ex nec. Sed ut choro saepe, sale augue sea et. His nemore dolorum mnesarchum at, ius an adipisci aliquando, laoreet placerat ea ius.
\ No newline at end of file
diff --git a/_posts/2018-01-12-elements.html b/_posts/2018-01-12-elements.html
index 4dae5e94f4..52854ebf6c 100644
--- a/_posts/2018-01-12-elements.html
+++ b/_posts/2018-01-12-elements.html
@@ -1,5 +1,6 @@
---
title: Elements Reference
+icon: fa-lightbulb
layout: post
---
@@ -258,4 +259,4 @@
Preformatted
i++;
}
-print 'It took ' + i + ' iterations to sort the deck.';
\ No newline at end of file
+print 'It took ' + i + ' iterations to sort the deck.';
diff --git a/_posts/2020-06-02-beginnings-of-dinobot.md b/_posts/2020-06-02-beginnings-of-dinobot.md
new file mode 100644
index 0000000000..acc5b0dd01
--- /dev/null
+++ b/_posts/2020-06-02-beginnings-of-dinobot.md
@@ -0,0 +1,123 @@
+---
+title: The beginnings of dinobot
+author: Teo
+layout: post
+---
+
Challenges of browser emulation with Selenium in Java
+
I got inspired to start this project after seeing a Youtube video about android game app automatization in Python. I decided to turn the difficulty up a knotch and attempt my first ever project in Java: a bot that plays the Google Chrome offline dinosaur game. This is how dinobot was born, and I'm very thrilled to see where it will lead, as I have many improvements in mind, but that's for another post. Now let's dive in!
+
+
Setting up: Creating a Maven project in Eclipse for the first time
+
Right of the bat I faced the difficulties, but nothing a few minutes ( or hours ) of googling couldn't solve. I learned how to set up a Maven project in Eclipse and with all the required dependencies for the Selenium imports I wanted using this tutorial.
+
+
Broswer Emulation
+
Needing to emulate Chrome I had to download the Selenium Chrome driver compatible with my current Chrome version. One of the first bugs I ran into was initializing the driver- inputing the its path did not seem to work, so I just ended up moving the executable into the dinobot project directory. The following code excerpt initializes the driver and starts up the bot.
The next code excerpt is from the main TRexBot class, that opens a new Chrome window and browses to the game's link.
+{% highlight java linenos %}public class TRexBot {
+ //class level variables
+ private ChromeDriver driver;
+ private WebElement window;
+ public TRexBot() {
+ }
+ // initialize a new chrome instance
+ private void initializeDriver() {
+ driver = new ChromeDriver();
+ }
+ private void initializeGamePage() {
+ // go to the chrome dino game page
+ driver.get("chrome://dino/");
+ // find the element we need to analyze
+ window = driver.findElement(By.cssSelector(".runner-canvas"));
+ new WebDriverWait(driver, 1000).until(ExpectedConditions.visibilityOf(window));
+ //add delay to for page be loaded before starting the game
+ checkPageIsReady(1000);
+ }
+ public void startGame() {
+ initializeGamePage();
+ // the start game function will be discussed later
+ start();
+ }
+ {% endhighlight %}
+
+
What I struggled with the most was line 15 from above: figuring out how to find the webpage element which reresented the container of the game itself. I inspected different parts of the page using Chrome Dev Tools and eventually found what I was looking for. I was only able to use the game canvas after a lengthy dive into the specific documentation. I cannot stress how usefull reading the docs is and how all of us need to do more of it.
+
+
+
+
Algorithm implementation
+
The game has very simple rules: dodge the incoming static (cactuses on the ground) or moving (bird) obstacles. The velocity of the dino increases as the game progresses, which would normally complicate things, but in our case it should not be a problem as we directly inject the webpage js script into our code to get the dino's current speed. This is the general JavascriptExecutor object:
+
+{% highlight java linenos %}private Object executeScript(String command) {
+ return ((JavascriptExecutor)driver).executeScript(command);
+ }{% endhighlight %}
+
+
Now let's see it in action! Using the java.util.Map as well as executescript I created an object that takes each one of the incoming obstacles visible in the horizon and maps it to their position on the oX axis. The position of the dino on the x axis, as well as it's current speed are also readily available upon returning more javascript code.
+{% highlight java linenos %}private Boolean isObstaclePresent() {
+ Map obstacle = (Map) executeScript("return Runner.instance_.horizon.obstacles.filter(o => (o.xPos > 25))[0] || {}");
+ Long tRexPos = (Long) executeScript("return Runner.instance_.tRex.xPos");
+ Double currentSpeed = (Double) executeScript("return Runner.instance_.currentSpeed");
+ {% endhighlight %}
+
+
Determining when to jump over an obstacle depends on the current speed of the dino and the distance from the dino to the obstacle. The default parameter was set to private static final int DEFAULT_DISTANCE = 0.
+{% highlight java linenos %}Long distanceToStartJump = firstJump ? new Long(DEFAULT_DISTANCE + 180) : new Long(DEFAULT_DISTANCE + 100);
+ //dynamically calculate the distance difference to
+ if(currentSpeed >= 10) {
+ distanceToStartJump = Math.round(distanceToStartJump + (20 * (currentSpeed % 10))) + 40;
+ }
+ //speed is > 13, space bar needs to be pressed in advance
+ if(currentSpeed > 13) {
+ distanceToStartJump += 50;
+ }{% endhighlight %}
+
+
Of course, there is no point in jumping if there is no obstacle so we check for one based on 2 conditions: the object obstacle cannot be empt and needs to have a position on the x axis. We check for this using the getKey method. If these 2 conditions are met, we calculate the currentDistanceToObstacle by subtracting the dino's position on the oX axis from the obstacles position. Now, if the dino is in the appropriate position to jump (line #) it will perform the action.
+ {% highlight java linenos %} // Check if obstacle is present
+ if (obstacle != null && obstacle.containsKey("xPos")) {
+ //If obstacle is flying, jump only if dino height >= vertical position of the obstacle
+ if (obstacle.get("width") == FLYING_OBSTACLE_WIDTH && obstacle.get("yPos") < TREX_HEIGHT) {
+ return false;
+ }
+ Long currentDistanceToObstacle = obstacle.get("xPos") - tRexPos;
+ if (obstacle.get("xPos") > tRexPos && currentDistanceToObstacle <= distanceToStartJump) {
+ if (firstJump) {
+ firstJump = false;
+ }
+ System.out.println("Identified Obstacle at "+ currentDistanceToObstacle);
+ return true;
+ }
+ }{% endhighlight %}
+
+
But how do we get the dino to jump in the first place. We use selenium's sendKeys method to input space.
+{% highlight java linenos %} private void jump() {
+ new Actions(driver).sendKeys(window, Keys.SPACE). build().perform();
+ }{% endhighlight %}
+
+
One problem to be aware of is that the bot might start 'playing' before the webpage has loaded. To combat that, I added a ```sleep``` fuction that delays the start of the page until the page is fully loaded:
+{% highlight java linenos %} private void checkPageIsReady(Integer time) {
+ try {
+ Thread.sleep(time);
+ } catch (Exception e) {}
+ } {% endhighlight %}
+
+
Now that we have the algorithm figured out, to start the game, the bot inputs space once than continues to jump if the obstacles are present. To avoid the while loop ordeal™ (we don't want the game to restart infinitely), I added an initial condition: the dino will only to dodge the obstacles as only until it loses.
+{% highlight java linenos %}private void start() {
+ firstJump = true;
+ jump();
+ while (!isGameEnded()) {
+ if (isObstaclePresent()) {
+ jump();
+ }
+ }
+ System.out.println("Your score is:" + getScore());
+ }{% endhighlight %}
+
+
All of the code is available on github. Keep learning and happy botting💖!
The overview of the plan is to use a neuroevolution algorithm NN to play the game instead of the bootleg algorithm I came up with that cannot be generalized that well over all states of the game. At first I was going to still keep the browser automation part and use my new algorithm to play the game in browser (and altho I might still do this in the future), for now I decided against it. Instead, I'm going to recreate a copy of the game in Java in order to learn more really. I have never created a game from scratch, so I thought this to be a good opportunity to do do. I have a dcent amount of experiences with DNNs, but only in Python so I'm excited to test my knowledge by applying libraryless. So without further ado, let's see the plan broken down into more digestible pieces!
+
+
Creating the game
+
Note: this is just a theoretical plan, the final project might end up being a little different.
+
There aren't many objects in the game so this simplifies things. I will have 2 main classes: one for the dinosaur itself and one for the obstacles.
+The dino class shall include the following variables: coordinates within a cartesian plane, size (width and heights), score etc.
+Now for the more phsysicsy part, I will need a container for velocity and gravity and jumping force. To determine weather the dino is dead or not, a boolean value isDead will be included.
+Now for the methods: the dino will be able to jump, duck, stand up and the score will update based on distance.
+
+
Now for the obstacles. There are two types: birds and cactuses. Each will have their own class that extends the main Obstacle.java class.
+Here we need to store the obstacle coordinates in the cartesian plane, size and movement speed (only for birdies). A method will check for collisions with the dino.
+
+
+
Neural Network Arhitecture
+
There will be 2 NNs one ofr each type of obstacle. The cactus NN inputs are the following: distance to obstacle, size of obstacle (width, height), dino's position on the oY axis and velocity. The bird NN will include all the following plus the position of the bids on the y axis and thier velocity. The outputs are: jump, duck, do nothing.
+
+
Genetic Algorithm
+
+
+
+
+
diff --git a/_posts/2020-06-26-data-structures.md b/_posts/2020-06-26-data-structures.md
new file mode 100644
index 0000000000..9878585d98
--- /dev/null
+++ b/_posts/2020-06-26-data-structures.md
@@ -0,0 +1,465 @@
+---
+title: Data Structures
+author: Teo
+layout: post
+---
+
What are data structures?
+
Data structure are specialized formats for organizing, processing, retrieving and storing data. While there are several basic and advanced structure types,
+any data structure is efficient in some operations and inefficient in others. Therefore, the goal is to understand them in order to pick the most optimal data structure
+for the problem at hand.
+
Commonly used Data Structures are the following (listed from the easiest to wrap your head around to the hardest in my opinion):
+
+
+
+
Arrays
+
Linked Lists
+
Stacks
+
Queues
+
Trees
+
Graphs
+
Hash Tables
+
+
+
+
+
+
+
Arrays
+
An array is the simplest and most widely used data structure. Other data structures like stacks and queues are derived from arrays. Here’s an image of a simple array of size 10, containing elements [10, 20, 30, 40, 50, 60, 70, 80, 90 and 100].
+
+
Each data element is assigned a positive numerical value called the Index, which corresponds to the position of that item in the array. The majority of languages define the starting index of the array as 0.
+
+
+
+
Types of Arrays
+
+
One-dimensional arrays (as shown above)
+
Multi-dimensional arrays (arrays within arrays)
+
+
+
+
+
+
Basic Operations on Arrays
+
+
Insert — Inserts an element at a given index
+
Get — Returns the element at a given index
+
Delete — Deletes an element at a given index
+
Size — Gets the total number of elements in an array
+
+
+
+
Array Processing Examples in Java
+{% highlight java linenos %}String[] dogs = {"terries", "pugs", "bulldogs", "samoyeds"};
+int[] = {1, 2, 3, 4};
+// Accesing an element of the array
+System.out.println(dogs[1]); // Outputs pugs
+// Change an element of the array
+dogs[1] = "beagles";
+System.out.println(dogs[1]); // Now outputs beagles
+// Size of array
+System.out.println(dogs.length); // Outputs 4
+}{% endhighlight %}
+
+{% highlight java linenos %}
+// Function to insert an element in arr at given index
+public static int[] insertElement(int[] arr, int index, int element) {
+ int[] result = new int[arr.length];
+ for(int i = 0; i < index; i++)
+ result[i] = a[i];
+ newarr[index] = element;
+ for(int i = index + 1; i < arr.length; i++)
+ result[i] = a[i - 1];
+ return newarr;
+}{% endhighlight %}
+
+
+
+
Linked Lists
+
A linked list is another important linear data structure which might look similar to arrays at first but differs in memory allocation, internal structure and how basic operations of insertion and deletion are carried out.
+
+A linked list is like a chain of nodes, where each node contains information like data and a pointer to the succeeding node in the chain. There’s a head pointer, which points to the first element of the linked list, and if the list is empty then it simply points to null or nothing.
+
+Linked lists are used to implement file systems, hash tables, and adjacency lists.
+
+
Here’s a visual representation of the internal structure of a linked list:
+
+
+
+
+
Types of Linked Lists
+
+
Singly Linked List (Unidirectional)
+
Doubly Linked List (Bi-directional)
+
+
+
+
+
Basic Operations on Linked Lists
+
+
InsertAtEnd — Inserts a given element at the end of the linked list
+
InsertAtHead — Inserts a given element at the start/head of the linked list
+
Delete — Deletes a given element from the linked list
+
DeleteAtHead — Deletes the first element of the linked list
+
Search — Returns the given element from a linked list
+
isEmpty — Returns true if the linked list is empty
+
+
+
+
Linkled List implementation in Java
+{% highlight java linenos %}
+import java.io.*;
+public class LinkedList {
+ Node head; // head of list
+ // Linked list Node. This inner class is made static so that main() can access it
+ static class Node {
+ int data;
+ Node next;
+ Node(int d) // Constructor
+ {
+ data = d;
+ next = null;
+ }
+ }
+ // **************INSERTION**************
+ // Method to insert a new node at end
+ public static LinkedList insertAtEnd(LinkedList list, int data)
+ {
+ // Create a new node with given data
+ Node new_node = new Node(data);
+ new_node.next = null;
+ // If the Linked List is empty, then make the new node as head
+ if (list.head == null) {
+ list.head = new_node;
+ }
+ else {// Else traverse till the last node and insert the new_node there
+ Node last = list.head;
+ while (last.next != null) {
+ last = last.next;
+ }
+ last.next = new_node; // Insert the new_node at last node
+ }
+ return list;
+ }
+ // **************TRAVERSAL**************
+ // Method to print the LinkedList.
+ public static void printList(LinkedList list) {
+ Node currNode = list.head;
+ System.out.print("\nLinkedList: ");
+ // Traverse through the LinkedList
+ while (currNode != null) {
+ // Print the data at current node
+ System.out.print(currNode.data + " ");
+ // Go to next node
+ currNode = currNode.next;
+ }
+ System.out.println("\n");
+ }
+ // **************DELETION BY KEY**************
+ // Method to delete a node in the LinkedList by KEY
+ public static LinkedList deleteByKey(LinkedList list, int key) {
+ // Store head node
+ Node currNode = list.head, prev = null;
+ // CASE 1: If head node itself holds the key to be deleted
+ if (currNode != null && currNode.data == key) {
+ list.head = currNode.next; // Changed head
+ System.out.println(key + " found and deleted");
+ // Return the updated List
+ return list;
+ }
+ // CASE 2: If the key is somewhere other than at head
+ // Search for the key to be deleted, keep track of the previous node as it is needed to change currNode.next
+ while (currNode != null && currNode.data != key) {
+ // If currNode does not hold key continue to next node
+ prev = currNode;
+ currNode = currNode.next;
+ }
+ // If the key was present, it should be at currNode
+ // Therefore the currNode shall not be null
+ if (currNode != null) {
+ // Since the key is at currNode
+ // Unlink currNode from linked list
+ prev.next = currNode.next;
+ // Display the message
+ System.out.println(key + " found and deleted");
+ }
+ // CASE 3: The key is not present
+ // If key was not present in linked list currNode should be null
+ if (currNode == null) {
+ System.out.println(key + " not found");
+ }
+ return list;
+ }
+ // **************DELETION AT A POSITION**************
+ // Method to delete a node in the LinkedList by POSITION
+ public static LinkedList deleteAtPosition(LinkedList list, int index) {
+ Node currNode = list.head, prev = null; // Store head node
+ // CASE 1: If index is 0, then head node itself is to be deleted
+ if (index == 0 && currNode != null) {
+ list.head = currNode.next; // Changed head
+ System.out.println(index + " position element deleted");
+ return list;
+ }
+ // CASE 2: If the index is greater than 0 but less than the size of LinkedList
+ int counter = 0;
+ // Count for the index to be deleted, keep track of the previous node as it is needed to change currNode.next
+ while (currNode != null) {
+ if (counter == index) {
+ // Since the currNode is the required position. Unlink currNode from linked list
+ prev.next = currNode.next;
+ System.out.println(index + " position element deleted");
+ break;
+ }
+ else {
+ // If current position is not the index, continue to next node
+ prev = currNode;
+ currNode = currNode.next;
+ counter++;
+ }
+ }
+ // CASE 3: The index is greater than the size of the LinkedList
+ // If the position element was found, it should be at currNode, Therefore the currNode shall not be null
+ if (currNode == null) {
+ System.out.println(index + " position element not found");
+ }
+ return list;
+ }{% endhighlight %}
+
+
Bonus: Arrays vs Linked Lists
+
🧠 In the array the elements belong to indexes, i.e., if you want to get into the fourth element you have to write the variable name with its index or location within the square bracket. In a linked list though, you have to start from the head and work your way through until you get to the fourth element. As a result, accessing an element in an array is fast, while linked list takes linear time, so it is quite a bit slower.
+
+🧠 Operations like insertion and deletion in array consume a lot of time. On the other hand, the performance of these operations in linked lists is fast.
+
+🧠 Arrays are of fixed size. In contrast, linked lists are dynamic and flexible and can expand and contract its size.
+
+🧠 In an array , memory is assigned during compile time while in a linked list it is allocated during execution or runtime.
+
+🧠 Elements are stored consecutively in arrays whereas they are stored randomly in linked lists .
+
+
+
+
+
+
Stacks
+
We are all familiar with the Undo option, present in almost every application. Ever wondered how it works? The idea: you store the previous states of your work (which are limited to a specific number) in the memory in such an order that the last one appears first. This can’t be done just by using arrays. That is where Stacks come in. Here’s a visual representation of the internal structure of a linked list:
+
+
+
A real-life example of Stack could be a number of pancakes stacked on top of each other. In order to get the extra syrupy pancake that’s somewhere in the middle, you will need to remove (or alternatively, eat) all the pancakes placed on top of it. This is how the LIFO (Last In First Out) method works.
+
+
+
+
Basic Operations of Stacks
+
+
Push — Inserts an element at the top
+
Pop — Returns the top element after removing from the stack
+
isEmpty — Returns true if the stack is emptyt
+
Top — Returns the top element without removing from the stack
+
+
+
+
Stack implementation in Java
+{% highlight java linenos %}
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+public class Stack implements Iterable {
+ private Node first; // top of stack
+ private int n; // size of the stack
+ // helper linked list class
+ private static class Node {
+ private Item item;
+ private Node next;
+ }
+ // Initializes an empty stack.
+ public Stack() {
+ first = null;
+ n = 0;
+ }
+ public boolean isEmpty() {
+ return first == null;
+ }
+ // Returns the number of items in this stack.
+ public int size() {
+ return n;
+ }
+ // Adds the item to this stack.
+ public void push(Item item) {
+ Node oldfirst = first;
+ first = new Node();
+ first.item = item;
+ first.next = oldfirst;
+ n++;
+ }
+ // Removes and returns the item most recently added to this stack.
+ public Item pop() {
+ if (isEmpty()) throw new NoSuchElementException("Stack underflow");
+ Item item = first.item; // save item to return
+ first = first.next; // delete first node
+ n--;
+ return item; // return the saved item
+ }
+ // Returns (but does not remove) the item most recently added to this stack.
+ public Item top() {
+ if (isEmpty()) throw new NoSuchElementException("Stack underflow");
+ return first.item;
+ }
+ // Returns a string representation of this stack.
+ public String toString() {
+ StringBuilder s = new StringBuilder();
+ for (Item item : this) {
+ s.append(item);
+ s.append(' ');
+ }
+ return s.toString();
+ }
+ // Returns an iterator to this stack that iterates through the items in LIFO order.
+ public Iterator iterator() {
+ return new LinkedIterator(first);
+ }
+ // an iterator, doesn't implement remove() since it's optional
+ private class LinkedIterator implements Iterator {
+ private Node current;
+ public LinkedIterator(Node first) {
+ current = first;
+ }
+ public boolean hasNext() {
+ return current != null;
+ }
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ public Item next() {
+ if (!hasNext()) throw new NoSuchElementException();
+ Item item = current.item;
+ current = current.next;
+ return item;
+ }
+ }
+}
+{% endhighlight %}
+
+
+
+
+
+
Queues
+
Similar to Stack, Queue is another linear data structure that stores elementa in a sequential manner. The only significant difference between Stack and Queue is that instead of using the LIFO method, Queue implements the FIFO method, which is short for First in First Out.
+
+
A perfect real-life example of Queue: a line of people waiting at a ticket booth. If a new person comes, they will join the line from the end, not from the start — and the person standing at the front will be the first to get the ticket and hence leave the line.
+
+
+
+
Basic Operations of Queues
+
+
Enqueue — Inserts an element at the end of the queue
+
Dequeue — Removes an element from the start of the queue
+
isEmpty — Returns true if the queue is empty
+
Top — Returns the first element of the queue
+
+
+
+
+
Queue implementation in Java
+{% highlight java linenos %}
+public class Queue implements Iterable {
+ private Node first; // beginning of queue
+ private Node last; // end of queue
+ private int n; // number of elements on queue
+ // helper linked list class
+ private static class Node {
+ private Item item;
+ private Node next;
+ }
+ // Initializes an empty queue.
+ public Queue() {
+ first = null;
+ last = null;
+ n = 0;
+ }
+ // Returns true if this queue is empty.
+ public boolean isEmpty() {
+ return first == null;
+ }
+ // Returns the number of items in this queue.
+ public int size() {
+ return n;
+ }
+ // Returns the item least recently added to this queue.
+ public Item peek() {
+ if (isEmpty()) throw new NoSuchElementException("Queue underflow");
+ return first.item;
+ }
+ // Adds the item to this queue.
+ public void enqueue(Item item) {
+ Node oldlast = last;
+ last = new Node();
+ last.item = item;
+ last.next = null;
+ if (isEmpty()) first = last;
+ else oldlast.next = last;
+ n++;
+ }
+ // Removes and returns the item on this queue that was least recently added.
+ public Item dequeue() {
+ if (isEmpty()) throw new NoSuchElementException("Queue underflow");
+ Item item = first.item;
+ first = first.next;
+ n--;
+ if (isEmpty()) last = null; // to avoid loitering
+ return item;
+ }
+ // Returns a string representation of this queue.
+ public String toString() {
+ StringBuilder s = new StringBuilder();
+ for (Item item : this) {
+ s.append(item);
+ s.append(' ');
+ }
+ return s.toString();
+ }
+ // Returns an iterator that iterates over the items in this queue in FIFO order.
+ public Iterator iterator() {
+ return new LinkedIterator(first);
+ }
+ // an iterator, doesn't implement remove()
+ private class LinkedIterator implements Iterator {
+ private Node current;
+ public LinkedIterator(Node first) {
+ current = first;
+ }
+ public boolean hasNext() {
+ return current != null;
+ }
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ public Item next() {
+ if (!hasNext()) throw new NoSuchElementException();
+ Item item = current.item;
+ current = current.next;
+ return item;
+ }
+ }
+}
+{% endhighlight %}
+
+
+
+
+
Tincidunt eu elit diam magnis pretium accumsan etiam id urna. Ridiculus
-ultricies curae quis et rhoncus velit. Lobortis elementum aliquet nec vitae
-laoreet eget cubilia quam non etiam odio tincidunt montes. Elementum sem
-parturient nulla quam placerat viverra mauris non cum elit tempus ullamcorper
-dolor. Libero rutrum ut lacinia donec curae mus vel quisque sociis nec
-ornare iaculis.
+
Hi, I'm Teo. I graduated with a B.Sc of Honors in Psychology, but my enthusiasm for learning and discipline have lead me to become a self-taught software developer.
+The rapidly changing field of CS turns out to be much better in satisfying my intrinsic thirst for knowledge.
+
Having always had a passion for math- mainly calculus, linear algebra and chaos theory, I see CS as a playground where I can let my analytical mind run wild and solve problems creatively.
+ My main focus is on Machine Learning, mainly Deep Neural Networks and Reinforcement Learning, as I'm fascinated with how approximations of n-dimensional polynomial functions are able to solve real world problems.
+
Outside of CS, my interests include music- self-taught pianist and hardcore Bach enthusiast, reading and philosophy.
+ One of my goals is to be able to carry on Freud's legacy and develop a mathematical way of studying the subconsciouns using ML.
Elementum sem parturient nulla quam placerat viverra
-mauris non cum elit tempus ullamcorper dolor. Libero rutrum ut lacinia
-donec curae mus. Eleifend id porttitor ac ultricies lobortis sem nunc
-orci ridiculus faucibus a consectetur. Porttitor curae mauris urna mi dolor.
+
Open to job opportunities and project collabs. Drop me an email below: