Pet project: chessboard UI – Day 1

Yesterday I decided to start a small project to practice my JS skills. The objective is to develop an interactive chessboard UI with React. I decided to give it a week of time, with 2-5 hours of programming every afternoon. Let’s see how far I can go!

I don’t have a clear idea of what degree of complexity I want to reach in terms of features (the existing UIs for popular chess websites are quite advanced, see lichess.org for example), but hopefully I’ll be able to move pieces on the board in the coming days!

The code is public on Github and can be found here: https://github.com/TimAstier/react-redux-chess


Day 1

I expected the first day to be quite a struggle because it had been about two months since I last opened a code editor. Fortunately I spend less time than expected with the initial configuration and soon I was all set up and ready to develop my first React component in the Storybook: an Empty black <Square />! Soon followed by a collection of <Piece />.

 

From there displaying a <Board /> was straightforward but still quite satisfying!

Screen Shot 2018-08-23 at 16.00.46
A soon-to-be-full-of-pieces chessboard

Displaying chess positions on the board was the funniest part of the day. I discovered that there is a convenient and standard way to store a complete chess position in a string, the FEN notation. For example, this is the initial position of a game of chess:

'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'

The first part of the string describes the pieces on the board, row after row. For example, ‘r’ stand for a black rook, and ‘K’ stand for a white king. Digits indicate a series of empty squares. Rows are delimited with ‘/’.

Since my <Board /> component had a renderSquares() method that renders the 64 squares of the board, all I needed was to render the squares based on the position described in FEN notation. I used a util function called positionToArrayOfPieces() to provide every ‘Square’ with its content.

renderSquares(position) {
    const squares = [];
    let index = 0;
    const arrayOfPieces = positionToArrayOfPieces(position);
    for (let i = 1; i <= 8; i += 1) {
      for (let j = 1; j <= 8; j += 1) {
        squares.push(
          <Square
            key={index}
            color={this.coordinatesToColor(i, j)}
            content={arrayOfPieces[index]}
          />
        );
        index += 1;
      }
    }
    return squares;
  }

And, voila! We have our starting position:

Screen Shot 2018-08-23 at 16.07.53

In the evening I did some research to find a way to avoid having to develop all the chess logic myself (chess is somewhat more complex than tic-tac-toe). It happens that most existing chess websites use a library called chess.js, so I will probably use it as well if I reach a stage where I can start playing a game of chess on this UI.

The one-week quest against sugar

After starting to feel the benefits of porridge, I was convinced that better eating habits could change a lot of things for the better in my life. So I asked Alice (my new nutrition coach) recommendations about what I could improve.

She gave me a fun challenge for the week to come: try and reduce my sugar consumption, banishing pretty much all industrial products containing sugar. She also asked me to do my own research about the benefits of avoiding refined sugar in favour of brown sugar. By doing this research I not only acquired some useful knowledge, but it also taught me how to do my own research about nutrition, something that I didn’t even consider doing before.

Without trying to be scientifically exhaustive, I discovered that:

  • Sugar is quite rare in the natural state (mostly fruits), but it’s fundamental for the brain and body. So thanks to Darwin we sapiens developed a very special taste for sweet things, to incite us to go deeper in the forests and look for more berries. This craving for sugar is now exploited by the food industry to sell more products.
  • Refined sugar is basically sugar with many useful nutrients removed from it.
  • Consuming too much sugar can potentially causes all sorts of health issues.

Alice told me to try and find new sugar sources by eating fruits, maple syrup, honey or dried fruit (I went all-in on dried cranberries as a snack during that week). She also suggested to try out a few recipes to treat myself from time to time, such as an avocado-based chocolate mousse, banana ice-creams and energy bars. I tried two of them so far:

IMG_3332
The chocolate mousse was a success!
IMG_3343
The energy bars were’t that bad either but there was a bit too much honey and it melted very easily. Need to retry this once I find a blender.

That week fighting against my crave for sugar was quite fun and it wasn’t as difficult as expected. Alice had warned me and said to take it easy if the crave was too strong. But I didn’t feel any specific lack of sugar (maybe the cranberries helped). But more importantly, I experienced a few positive things:

  • My sense of smell improved. For example, walking past the bakery brought all kinds of new images in my mind (OK, that might have been a consequence of a lack of sugar…).
  • I started to eat a lot more fruits.
  • I was able to better appreciate the sweet taste of fruits.
  • I started to feel when things were ‘too sweet’.
  • If I remember well I started to sleep better around this period as well.

Another major positive point is that I realised that I could keep learning about nutrition by myself and try out new recipes. I became actively interested in the subject of food, cooking and nutrition.

The next step in my nutrition adventure came from reading a book called In Defense of Food: An Eater’s Manifesto. I will share the main ideas and the consequences it had on my eating habits in the next post.

In the beginning came the porridge

Everything happened one evening at the climbing gym. The place was about to close and a friend (let’s call him Kevin) working in the staff gently offered me and another friend (let’s call her Alice) a bowl of porridge. I had never eaten porridge before. It was delicious. Kevin and Alice were quite surprised and started asking me questions about my eating habits. It took them a few seconds to realise the gravity of the situation…


Of course I’ve always known that nutrition was important. I was also slightly interested in the topic. For example, I used to watch a few videos from a rock-climbing Youtuber exposing his view on nutrition. Still, I never considered the subject too seriously. But now it was different. It was clear that I needed a proper food education.

A few days after this realisation, I went online and looked for porridge recipes (like this one). This was literally my first time watching a cooking video. I discovered what chia seeds are (hey, new friends!) and I started eating porridge every morning. My classic recipe has a base composed of 1/3 cup of oats, warmed up in water with a pinch of salt (pro-tip from Alice – it can be soaked overnight. See here an article about the benefits), augmented with chia seeds, greek yogurt or milk (now replaced with almond or soya milk), honey (now replaced with maple syrup or marmalade) and all sort of things for topping (dark chocolate, almonds, bananas, strawberries, blueberries, the sky is the limit!)

40285206_1044384149070539_2520753212676374528_n
Best way to start the day

The ‘porridge benefits’ came quickly:

  • Breakfast was now a real feast: delicious and varied.
  • I had a new reason to wake up in the morning.
  • For the first time in a while I was feeling energetic during the whole morning.
  • My digestion improved (you don’t want more details).
  • My interest in food and cooking was starting to grow and I was appreciating eating good food again.

I’ve eventually became a fierce defender of the porridge community and I highly recommend it as a breakfast idea to anyone who haven’t tried it yet!

 

What I used to eat and the start of my nutrition revolution

From January 2017 to June 2018 I was working like a machine on a personal project and I gave little thought to what I was eating. My diet was composed almost exclusively of:

  • breakfast: a cup of coffee and some nutella spread on some of those Swedish crackers (wasa), or some muesli with milk
  • eating outside once a day: pizzas, sushis, salads, burger-king, often in take-away
  • very basic home cooking: pastas/rice with pesto or tomato sauce, pork chops, chicken breasts, beef steaks, frozen vegetables or veggie mixes and sashimi
  • snacks composed of cookies or milk chocolate

Looking backwards from where I am now, a few points (pretty obvious for most people) stand out about this diet:

  • Not healthy: lack of diversity, fast food, processed food, quite ‘greasy’, not organic
  • Produces tons of wastes from the packagings and boxes
  • Not environmental-friendly
  • Almost no fruits and very low on vegetables
  • Quite pricy
  • Not considering animal suffering (spoiler alert for my current experience with veganism)

From an external point of view though, I wasn’t looking that bad. I had been eating in a very healthy way since I was a child (thanks mom!) and I always exercise a lot. I can’t tell how exactly this diet impacted my health but I’m pretty sure it played a critical role in the depressive state I was in, as well as in the apparition of a few weird body symptoms that I’m not sure I want to talk about here.

In late June 2018 I realised that it was time for a change. OK, some friends rightly suggested that I needed, I quote, a proper food education. I don’t know if it sounds rude, but they were right (many thanks to them!). So I decided to start a personal nutrition revolution. And there came the porridge, and the very first step from getting back to reality and out of depression.

 

Going beyond ‘ten in a row’ at the cup-and-ball game

Ok. This one is a silly challenge I had in mind for quite some time. The rules are simple. Take the most simple, straightforward, seemingly meaningless game ever created – the French bilboquet – and do ten in a row.


Well, this story is pretty short. I used to play this game a little bit when I was a kid.  But I never did more than eight or so in a row. So I wanted to see if I could break the limit of ten in a row (don’t ask why).

In just two 5-minute sessions, the challenge was completed (hurray! I can now move on with my life).

2018, August 12: Seven in a row!

2018, August 18

This was a bit weird but I was out of my shower and feeling inspired after reading about ‘living in the present moment’ from the book Become what you are. I tried to keep what I had just learnt in mind while trying this silly challenge one more time – and tadaa! – fifteen in a row:

Good-bye, Mr. Bibloquet! I’m done with you… until the next challenge!

 

Keeping up with the flow

On July 4th 2018 I experienced for the first time a conscious flow situation. I was climbing at the bouldering gym and I was enjoying the climb in a very unique way. Everything felt easy. I felt in total control of my body and mind. The moves came naturally. I was focused on nothing else but the climb. It was a kind of ecstatic trance in which I was feeling at the top of my capacities, truly alive and absorbed in the moment.


I was working on a 7b+ project that I had been trying for already 3 sessions (about 20-25 tries). Suddenly I felt that this was the moment. I set up my phone to record the attempt, and the project was completed:

2018, July 4th, 11:02 AM

After this success I continued my session and I was still feeling pretty good. I felt so in control that I tried to redo on camera a 7c problem that I had succeeded only once (after many tries) and that I failed many other times since: the move in the middle is quite demanding for me and requires great coordination. Nevertheless, the attempt resulted in one of my smoothest send ever:

2018, July 4th, 11:18 AM

I was so hyped that I left my phone at the same place to try and record another 7b+ project that I had tried many times without success. And to my surprise, this one worked as well (although there was quite some struggle!). At this point I was not believing what was happening.

2018, July 4th, 11:21 AM

Those three success happened within twenty minutes. I was very confused. After the session the word flow came to me to express this feeling. It is only later that I discovered that flow is a concept used in psychology to describe this exact sort of situation. Here is a definition from wikipedia:

The mental state of operation in which a person performing an activity is fully immersed in a feeling of energized focus, full involvement, and enjoyment in the process of the activity. In essence, flow is characterized by complete absorption in what one does, and a resulting loss in one’s sense of space and time.

This concept of flow was named by Mihály Csíkszentmihályi in 1975. In his book on the topic (Flow: The Psychology of Optimal Experience), Csíkszentmihályi uses many descriptions of ‘flow’ situations coming from rock-climbers and chess players. As both a rock-climber and a chess player, this reading was for me a revelation.

Since that day I started learning about what flow is and how to reproduce this mental state in various situations of the everyday life (other hobbies, work, household tasks, interactions with people, etc.). Doing so tremendously improved my quality of life.

How coaching other climbers improved my climbing and my life

As soon as I started to genuinely care about  helping my friends to become better climbers and doing research for this purpose, I learnt many useful things that tremendously improved both my own climbing and quality of life. A key reading for me was the article Train Like a Pro in which an apprentice climber describes his experience when training with Coach Sjong, the so called Climbing Sensei.

“Nearly everything Sjong says is eye-opening and brilliant. He changes your entire perspective on climbing technique five times per session. He is indeed, a sensei.”

Coaching is a skill

I used to misunderstand what being a good coach means. To me, it was obvious that if I was a better climber (if that means anything at all), I would be able to give useful advice to someone climbing on lower grades. This happens to be completely wrong. I might be a rather good climber but I used to be a terrible coach.

What happened is that I realised that the way I was coaching people was close to simply showing off. For example, I used to rely too much on showing the moves myself or giving away answers too quickly. I don’t think this approach was truly beneficial to anyone. The new approach I use now is much more satisfying, efficient and fun. It can be described as follow:

  • Start from understanding the strengths and weaknesses of the climber. Has they climbed before? What kind of climbing (indoor/outdoor, lead-climbing, bouldering, etc.) How do they do in terms of strength, power, balance, technique, flexibility, finger strength, overall fitness? How motivated are they to make progress?
  • Learn to know them as a person. Build an authentic relationship and understand their fears, personality or mental images that might impact their climbing as well as the relation between coach and apprentice.
  • Design personalised exercises to allow them discovering new situations, new problems and work on their weaknesses.
  • Be a good observer and guide. Observe them climbing, listen to their observations and ask them questions such as ‘what happened there?’ or ‘what do you think you could do differently?’ to guide them and allow them to develop their own thinking.
  • Try and avoid showing moves or giving away answers too quickly. This is similar to the Eastern way of teaching calligraphy, martial arts, philosophy, etc.
  • Don’t assume that you know everything. I can learn things to improve my own climbing even from a complete beginner.
  • Victory checks, or any friendly sign between climbers or coach and apprentice are a good way to celebrate achievements (like toping a problem). It rapidly becomes a ritual and it brings everybody a little more into the ‘pack’ or the climbing community. As a coach, I try to give more values to those checks by only giving or accepting them when people genuinely did something beyond their usual comfort zone.
40112106_322862561617903_2047812828747792384_n
Bouldering outdoors near Stockholm. Credits to Alice De Schutter

There’s nothing wrong with not being a pro

I used to feel a little uncomfortable or even envious when comparing myself to pro-climbers. Those people enjoy climbing so much that they are able to devote their life to it and even do it for a living. Why can’t I do the same? This was obviously a childish reasoning and I now understand two things.

First, I have many hobbies and other priorities in life and I’m much happier spending time doing many things instead of focusing on climbing only. I also doubt that I would be able to survive for a long-time if I had to live from my climbing skills!

Second, I don’t have to ‘be a pro’ (whatever that means) to enjoy climbing for what is is. The only purpose of climbing is climbing. I like climbing, and that’s the only thing that matters. I can continue making progress (or not!) and enjoying the feeling of climbing without having to devote my life to it.

The funny thing is that because of this barrier I had in my mind before, I used to be always a little shy when talking to climbers way stronger than me. Now that I understand that ‘there is nothing wrong with not being a pro’, I’m actually having good times with really good climbers (and pros!) at the different gyms I’m climbing at. And I’m learning a lot from them.

Focusing on the outcome is not a good strategy

Here is a quote from the article mentioned in the introduction:

“Leading 5.11a isn’t a goal. It’s an outcome. The goal is to address your weaknesses. If we are successful, the outcome will be climbing 5.11a. You can achieve the outcome without reaching your goals or vice versa, but you’ll grow more as a climber in the long term if you achieve your goals.” – Coach Sjong

It doesn’t seem like much at first but this was actually huge for me. So much so that I started applying this to my own life and realised I was definitely focusing too much on fame, money or personal achievements. Now I know that by focusing on achieving my own goals, I’m growing more as a human.

The weakest link principle

This is related to the previous point (the goal is to address your weaknesses). I found that this principle makes a lot of sense in climbing since it’s very easy to understand in the context of this sport.

In bouldering, the aim is to complete a problem by climbing to the top. You either succeed or fail. There is no in-between possibility. So the feedback is objective and immediate.

What makes bouldering so interesting is that there are always many ways in which a problem can be solved. Different people will come up with different ideas of move order or moves that might all result in a success. As everybody has different natural strengths and preferences, the natural tendency is to rely on their main strength to solve problems. For example, I used to over-use mu upper-body strength to power through problems.

The issue with this approach is that different problems are oriented towards specific skills that, if used correctly, will make the climb easier and much more efficient. For example, powering through a technical problem on a positive wall with small footholds isn’t a really good idea. And this is were the ‘weakest link principle’ comes into play. I can increase my overall climbing level tremendously if I focus on my weaknesses.

A small change in your weakest areas will have a great effect on overall performance, while a significant improvement in the strongest areas will have a much smaller effect. For this reason, maximizing improvement requires discovering your weakest areas and targeting them as your top training priorities.” – Coach Sjong

Here is a list of different skills required to be a balanced climber, ordered by my personal situation. Since I started focusing on my weaknesses, a lot changed in my climbing.

  • Power (Although there is nothing as too much power.)
  • Analysis / Creativity (Being colour-blind forces me to think a little…)
  • Technique (I used to underestimate the importance of feet placement for a long time. Coaching other climbers is helpful to better understand concepts that have already became habits but can still be made more efficient.)
  • Finger strength (I started to train it this week for the first time, but it was already quite good since I started climbing at an early age.)
  • Flexibility (Now stretching in the morning and after sessions. Also working on the split.)
  • Focus / mental (This introspection work is helping a lot.)
  • Nutrition (How to eat in a more healthy way or what to eat to recover after sessions. Cooking a selecting healthy food is has become a new hobby!)
  • Stamina (I should do more lead-climbing and activities such as running or swimming. But this is not that useful for bouldering.)

Applying the same principle to my life, I’m now focusing more on vital activities that I haven’t been too much concerned about until then, such as cooking, helping others, learning practical things (such as how to do household tasks or gardening), expressing my feeling, observe and care about nature, cultivating friendship, etc. And as in climbing, I can see promising results.

Training

With this new goal of addressing weaknesses in mind, training became a lot more fun. I started doing research on specific exercises or routines that I can do to improve on specific areas. For example I’m currently training my finger strength.

Training is very satisfying because I can easily measure my progress by taking notes of my performance session after session. Moreover improvements are noticeable when going back to the climbing wall.

Warm up and stretching is essential

I used to underestimate the importance of warming up and stretching before and after the sessions. A good warm up tremendously improve my quality of climbing. I’m a lot more precise on my footwork and I feel my body in a much different way, getting in flow situations a lot more easilySimilarly, stretching after sessions is key to recover faster, reduce the risk of injuries and being able to do more sessions per week.

In my personal life a parallel can be drawn with the importance of having a morning and night routine.

Balance is everything

Here is another quote from the conversation between Coach Sjong and his student:

“What do you think footwork is?”

“Using your legs to move your body up the wall?”

“Incorrect. Your knees move your body up and down. Your feet and your toes manage your hips. […] You can use your toes to pull your hips into the wall. You can pivot your feet to swing your hips into a different position. Our hips are roughly our center of gravity. Our center of gravity controls our balance. Balance is everything.”

Every bouldering problem can be solved using a myriad of different approaches using different skillsets. But no matter what the approach is, balance is the common factor. You can’t climb to the top if you are not balanced or if you lose your balance.

I find this advice to be of inestimable value when applied to life in general. Everybody is free to live the life they want to have and become who they want to be. All I need to do is to find the correct balance. This concept is also related to the concept of harmony (thinking about the constant balance between Yin and Yang energies, for example).