Category Archives: Learning

Program your mind thru your body

How you sit, stand, and move can affect your decision making and attitude.

You probably aren’t even aware of how you sit and stand a majority of the time. Most people are not mindful of their posture. These are some common mistakes people make with their body that lead to poor outcomes:

  • Slouching
  • Frowning
  • Crossing their arms
  • Looking down

Try these changes to make for a better day.

Smile, even when on a phone call.

Forcing yourself to smile, even when you don’t feel like it will make you feel happier and more confident.

There is a connection between what we show on our face and how we actually feel. Surprisingly it actually goes both ways. If you change your expression it will actually start your internal feeling moving to match it.

The positivity will come thru your voice as well.

Check in on your posture.

Then correct it.

Try to form the habit of thinking about your posture about once an hour or so. Look up proper posture and do your best to mimic it. Good posture will help prevent back pain, help you breathe properly, and make you more attractive.

You may need to strengthen some muscles to correct bad posture.

Try “power poses.”

It sounds silly, but it works.

Sitting and standing like a person with power will change your mood to feel more confident and assertive.

  • Stand like a superhero (chest out, hands on hips).
  • Lean back in your chair with your feet on the desk (like the Boss).
  • Put your hands in the air in a V shape like you are celebrating.

Change your body and you will change your mind.

What to say when life gets in the way

You say, “That is to stop everyone else.”

Too many people give up at the smallest of speed bumps. They do not stick with their goal long enough to find success. Instead they turn to the siren call of easy dopamine.

But the rewards are on the other side of the difficulty.

Let the roadblocks be your guide.

Ryan Holiday literally wrote a book on this called “The Obstacle Is the Way.”

When life throws a monkey wrench into your plans, that’s how you know you are on the right track. And life doesn’t pull punches. This can take the form of any number of things:

  • Car accident
  • Loved one gets sick
  • Water leak in your home
  • Lose your job

Just don’t let the problem derail you from your goal.

Attach emotion to the goal.

Part of the reason people give up easy is they don’t have any emotional associated with their goal.

The despair, annoyance, and frustration of the challenges in the way are enough to overwhelm some half hearted want. You need to genuinely desire the outcome you want. What will it mean for you to achieve this goal? A better life for your family? Freedom?

Some people say to find a “why”. What they really mean is attach an emotion to your outcome.

Remember why the obstacles are there.

They are to stop everyone else.

Everyone who doesn’t really want the goal. The walls and difficulties are there to turn them towards what they do want. But you know what you want. So they won’t turn you.

You will break thru the walls and get to your goal no matter what life throws at you.

The Faster Way to Learn a Skill

I usually spend too much time watching and reading before doing.

You want to do things right. So you go thru tutorials, watch videos and read how to articles. These make you feel like you are learning. And you are learning some.

But it is really procrastinating because you want to be perfect.

Learn as you go.

If you are waiting until you know enough, you will plod along barely making progress.

You want to learn just enough to take the next step. Steady action in the pursuit of your goal and the failures that will come with it are the largest sources of information.

If you want to learn, try without worrying about failing.

Get in your reps.

Classic education has ingrained a lot of people with the false idea that you only get a few attempts at something before you have failed for good.

The reality is, as long as you avoid doing something incredibly stupid, you get as many attempts as you like. The more attempts you make, the better you will be at the skill.

The more you try, the better you will get.

Do the thing poorly.

Be willing to get a beginner’s result.

One of the reasons you procrastinate by reading and watching is you are worried too much about the outcome of your first few attempts. For the first several tries, don’t worry so much about the end result as the process of creating it.

Getting the beginner’s result is the first step to getting mastery.

The 3 Things You Need to Succeed as a Trader

Anyone can make money trading.

There are successful traders with all sorts of strategies. Some go long. Some go short. Some trade futures. Some trade stocks.

But all of the traders who find success long term have an edge, risk management, and self awareness.

Find a statistical edge in the market.

Trading is like playing poker, you need to take the opportunities where the odds are in your favor.

There are professionals who make a living playing poker. They don’t make a living by winning every hand. They make a living by playing the odds out over thousands of hands. The same is true for stocks. You can make money by being right only half the time.

You just need to know over a thousand trades that you can make more on the half that your are right than the half you are wrong.

Don’t blow up your account.

The most common cause of failure in trading is people losing all of their money on a few trades where they got stubborn.

There are a few common risk management strategies out there but the most common I have come across is you should never have more than 1-2% of your account at risk on any one trade. If you have $1,000 that means you can take a maximum loss of $10-$20 on a trade before you should be out.

Managing your risk will keep you in the game long enough for the odds to work in your favor.

Beware your ego.

Many traders lose way more money than they should because they don’t want to take a loss.

Fear and ego are two of the main culprits. You fear that if you get out, the stock will turn around in your favor. You don’t want to lose money and be wrong. Revenge trading after a big loss to make it back often compounds the mistake. The ability to be detached from the outcome of each individual trade is a super power.

For beginners, or anyone who has not become profitable yet, you should set a max loss per day on your account to protect yourself from yourself.

How you should choose your goals in order to grow

Most people choose goals because the end result is the thing they want.

The problem is that most people have never really sat down and figured out what they want. They are chasing things that society has told them would be good to have. Or that they envy other people for having.

Some common goals:

  • More money.
  • Nice house.
  • Better job.

Setting a goal for the end result is a recipe for misery.

Because the feeling you get from the end result will be fleeting.

The good feeling we get from achievement or reaching our target is a big rush of dopamine. This will last for a short while before our baseline is reset. When that happens, we will not be any happier than before we got what we were chasing.

So here is a better way to set goals:

Set your goals by how you will have to change to achieve them.

Think about the kind of person you want to be.

Choose a goal that, in the pursuit of it, will force you to grow into that person. What skills do you want? Choose a goal that will force you to learn them.

The end result will still be a reward, but now the journey will be just as rewarding.

Who you become is more important than what you have.

This is why many lottery winners or people who come into quick wealth lose the money. They didn’t grow into their wealth. But now that you know, you can set better goals and grow into the person you want to become.

I Taught My Dentist How to Get People to Read His Marketing Mail

Tons of businesses make the same mistake as my dentist. They send out B Pile marketing mail.

Legendary marketer Gary Halbert had a concept he called A Pile, B Pile. When people get their mail, they sort it into 2 piles. Pile A is what they will open and read. Pile B goes straight in the trash.

You know B Pile mail:

  • New Credit Card Offers
  • Extended Warranty Notices
  • Obvious Business Postcard Adverts

Businesses spend thousands of dollars creating and mailing ads out just to have them thrown away unopened.

Because they look like an ad.

When I told my dentist about this, he laughed because he had just sorted thru his own mail the same way just an hour earlier. Standing next to the trash can throwing out everything that looked like an advertisement.

Here’s how you get into the A Pile:

Place your mail in a standard envelope with a first class stamp.

This will help it look like it came from and individual, not a business.

It may be more expensive, but right now you are spending money to put paper in people’s trash cans. Unread paper. Avoid the envelopes with the little windows and avoid postcard style mailers.

If you can, pay someone to hand address the envelopes.

Very few people will throw away a hand addressed envelope without at least opening it.

Second best is a cleanly printed name and address. The key here is to not make your marketing mail look like marketing mail. Remember the added cost will be returned by significantly higher open rate.

Add some way to track responses.

Doesn’t matter if its a unique coupon code, a text signup, or a website url to visit.

You need some way to see how effective you mail is being. Otherwise how will you know if you are wasting your money.

Many thanks to Gary Halbert for sharing this wisdom.

What I Learned Hiring a Developer on Fiverr to Make a Game

I was not nearly as detailed in my instructions as I thought I had been.

I made the mistake of comparing a feature I wanted to a feature in an old game. There is a new game with the same name that comes up in a search that is completely different. I hadn’t looked up the game of course because I knew what I was talking about. This made me feel a little silly.

When you are hiring someone else to make something for you, you must be extremely clear with what you want.

You cannot have too much clarity when describing something to a programmer.

If you are vague, you will either get their best guess or they will wait for clarity before continuing.

Time is money when you hire someone else. It could even be your time as you manage them. In this case, the first version of the game the developer created was not even the right genre. If you have high clarity, you will get what you want in a timely manner.

Here is how you create clear instructions for fiverr contractors.

#1. Google your own instructions and examples and see what the first result is.

If the developers are not familiar with what you are talking about, this is likely the first thing they will do.

After you Google this, grab the links to the sites that have the info you think will be relevant and add them to your instructions.

#2. Add images to your instructions.

Visual references add so much value to your written instructions.

Get the Google images results from the same searches that you did in step 1 and add them to your instructions.

#3. Ask a friend or family member what they think each instruction means.

Not everyone thinks the exact same way. See if you can have someone else tell you what they think you mean from your instructions.

After several passes I finally ended up with a game surprisingly close to what I had envisioned. You can get something built too if you will take the time to make it clear what you want.

How to Prototype a Card Game

There are 3 easy ways to prototype a card game.

After your initial design of the game, you need to playtest. To playtest you need a prototype. You need cards you can shuffle, move around on a play surface, and visibly recognize.

Here are three ways you can get started testing out your card game idea at home.

  • Use Card Blanks and Dry Erase Markers
  • Use Cards from Other Games and a Legend
  • Use Printed Cutouts and Card Sleeves

Use Card Blanks and Dry Erase Markers

This is a great option.

Easy to change cards around as you discover flaws in your game. It can be fast to get setup and is very flexible.

If this is your first time making a game though, you likely won’t just have card blanks laying around. Add to this that these could smudge as they are being shuffled and handled (card sleeves might help with this).

Use Cards from Other Games and a Legend

Use regular playing or poker cards, Uno cards, MTG commons, whatever works.

Make a paper or digital map of physical card to card from your game. Digital works better for changes as you are iterating and testing. This can be a little clunky as you have to reference back to the guide every so often for each card.

Use Printed Cutouts and Card Sleeves

This is the option I most recently tried out.

Its great because you can create a custom layout to get a feel for how your cards will actually look. The card sleeves let you use standard paper to save on printing cost. I recommend using a laser printer and going with black and white.

It is a little time consuming to set up at first and to cut out all of the templates. But the result is a great prototyping experience.

You can put old playing cards behind your cutouts in the sleeves to make them easier to shuffle. And you can use pencil on the templates to allow for changes as you test.

How To Succeed in Business and in Life Like Tom Bilyeu

Tom Bilyeu has achieved amazing success in multiple unrelated businesses. Billion with a “B” levels of success. How did he do it? He follows a process that he calls the “Physics of Progress”

Foundational Rule

Before you start the process you have to follow a foundational rule.

“Avoid a mortality event.”

Don’t do something, that if it fails, will take you out of the game. Don’t risk everything on a single play. With this in mind you can begin the process.

The Physics of Progress

Step 1: Decide what you want with high levels of clarity.

Set a clear goal and a date. You should be so clear about what your goal is that what you should do in the next 15 minutes is obvious. Even if the next step is googling about things you don’t understand.

Step 2: Identify the problem between where you are at and where your goal is.

If it is a new problem, then you need to be able to solve new problems. Or you need to be able to hire someone who can solve this problem for you.

Step 3: Come up with your best guess as to how your are going to solve the problem keeping you from your goal.

Remember the foundational rule: this should not be something that could ruin you or “kill” your chances.

Step 4: Try out your best guess and see if by implementing it you can solve the problem.

If your guess from Step 4 works, great you are done. Its working and you are achieving your goal. If not, you have learned and now you run thru this process again with the new information.

Remember, this is a loop. You are meant to go thru it more than once.

You can see Tom talk about this process yourself here: https://www.youtube.com/watch?v=HkSy218Aosc

Shadow Casting for Field of View in 2D Games in Phaser JS

Kind of a long title, but that is exactly what this post is about. I will walk thru an implementation of a 2D shadow casting algorithm in JavaScript for a Phaser JS game.

What Is Shadow Casting For?

What is this useful for? Well in my case, I have a turn based tactics game where I want fog of war and limited visibility based on the terrain. The player’s field of view (or FoV) should only include squares that units that the player controls can see.

Some people also use this type of algorithm for determining which squares are “lit” in a dungeon by a light source.

How Does It Work?

The basic idea is you cast a “ray” down a diagonal and then sweep it across to another diagonal. Anytime you hit something that is marked as a wall (anything you can’t see thru), you stop. That object then casts a shadow along the ray that hit its edge behind it, blocking the view.

There is a somewhat more thorough explanation for it at this website, which is where I adapted my code from (the code there is in python).

The Code

class FovShadow {
    constructor(two_d_map, tile_size, map_offset) {
        this.map_tiles = {}
        this.map = two_d_map
        this.tile_size = tile_size
        this.map_offset = map_offset
    }
}

As you can see this is the constructor of the class. It takes in a two dimensional array representing the map tiles, how many pixels wide a tile is and an offset from the edge of the game screen where the map starts. The last two values are important for determining which tile a unit is on when running the algorithm against its position. The map_tiles variable will hole which tiles are visible to the player.

getVisibleTiles(unit, vision_reset) {
        if(vision_reset) {
            this.map_tiles = {}
        }
        let origin = { x: Math.floor((unit.x - this.map_offset.x) / this.tile_size),  y: Math.floor((unit.y - this.map_offset.y) / this.tile_size) }
        this.markVisible({depth: 0, column: 0}, origin, 0)
        for(let i = 0; i < 4; i++) {
            let first_row = new ScanRow(1, -1, 1)
            this.scanRowForVisibleTiles(first_row, unit.sight_range, origin, i)
        }
    }

This is the function that is called whenever we need to update which tiles are visible. If we moved a unit, we will need to reset the vision.

We determine which tile the unit is on based on their x and y position in the game, the tile size and the offset of the map. Then we mark the tile they are standing on as visible. Finally we begin scanning for visible tiles in each direction (up, right, down, and left).

class ScanRow {
    constructor(depth, start_slope, end_slope) {
        this.depth = depth
        this.start_slope = start_slope
        this.end_slope = end_slope
    }

    getTiles() {
        let row_tiles = []
        let min_column = Math.floor((this.depth * this.start_slope) + 0.5)
        let max_column = Math.ceil((this.depth * this.end_slope) - 0.5)
        for(let i = min_column; i <= max_column; i++) {
            row_tiles.push({ depth: this.depth, column: i })
        }
        return row_tiles
    }

    nextRow() {
        return new ScanRow(this.depth + 1, this.start_slope, this.end_slope)
    }
}

export default ScanRow

We take a short break from the FovShadow class to define the supporting class used by the code that scans for visible tiles, the ScanRow class. A ScanRow represents a row or column of tiles. It is represented by 3 values.

The depth is how many rows or columns removed from our starting point we are. The start and end slopes represent the slope (think geometry slope or algebra slope, its math time) of the rays that mark the diagonals of our field of view between obstacles or the edges of the quadrant we are scanning.

If you can see past a tile, you would call “nextRow()” to recursively begin looking at the next row. Now back to our Shadow Casting class.

    scanRowForVisibleTiles(row, max_depth, origin, direction) {

        if(row.depth > max_depth) {
            return
        }
        let prev_tile = null
        let tiles = row.getTiles()
        for(let i = 0; i < tiles.length; i++) {
            let cur_tile = tiles[i]
            if(this.isWall(cur_tile, origin, direction) || this.isSymetric(row, cur_tile)) {
                this.markVisible(cur_tile, origin, direction)
            }
            if(prev_tile && this.isWall(prev_tile, origin, direction) && this.isFloor(cur_tile, origin, direction)) {
                row.start_slope = this.getSlope(cur_tile)
            }
            if(prev_tile && this.isFloor(prev_tile, origin, direction) && this.isWall(cur_tile, origin, direction)) {
                let next_row = row.nextRow()
                next_row.end_slope = this.getSlope(cur_tile)
                this.scanRowForVisibleTiles(next_row, max_depth, origin, direction)
            }
            prev_tile = cur_tile
        }
        if(this.isFloor(prev_tile, origin, direction)) {
            this.scanRowForVisibleTiles(row.nextRow(), max_depth, origin, direction)
        }
    }

This is our recursive function to go through rows and columns (all called “rows” here) and mark tiles that we can see. We only go as far as our unit can see (they have limited sight range), represented by “max_depth”.

For each tile in our ScanRow, we first check to see if the tile is a Wall, meaning we can’t see thru it. If it is, we mark it as visible. If this tile is a Floor tile and the previous tile we checked is a Wall tile, we need to reset our vision slope and go one step further away. Another way of saying this is, if the tile you are looking at is a Floor and the last tile you looked at is a Wall, look past the Wall. Check what is on the other side.

If the tile you are looking at now is a Wall and the previous tile was a Floor tile, we need to check the next row and limit it to the slope or angle from our origin to the Wall we hit.

If we finished scanning the row and the last tile we looked at was a Floor tile, look at the next row.

That is the basic logic of the Shadow Casting algorithm.

I will include the helper functions below in case you want to implement this yourself. As a note, this is all prototype code and was not written elegantly or efficiently.

    isWall(tile, origin, direction) {
        let coordinates = this.getMapXYCoordinates(tile, origin, direction)
        if(coordinates.y >= this.map.length || coordinates.y < 0) {
            return true
        }
        if(coordinates.x >= this.map[coordinates.y].length || coordinates.y < 0) {
            return true
        }
        return (this.map[coordinates.y][coordinates.x] === WALL || this.map[coordinates.y][coordinates.x] === DOOR_CLOSED)
    }

    isFloor(tile, origin, direction) {
        if(!tile) {
            return false
        }
        let coordinates = this.getMapXYCoordinates(tile, origin, direction)
        if(coordinates.y >= this.map.length || coordinates.y < 0) {
            return false
        }
        if(coordinates.x >= this.map[coordinates.y].length || coordinates.x < 0) {
            return false
        }
        return (this.map[coordinates.y][coordinates.x] !== WALL && this.map[coordinates.y][coordinates.x] !== DOOR_CLOSED)
    }

    isSymetric(row, tile) {
        return (tile.column >= row.depth * row.start_slope && 
            tile.column <= row.depth * row.end_slope)
    }

    markVisible(tile, origin, direction) {
        if(!tile) {
            return
        }
        let coordinates = this.getMapXYCoordinates(tile, origin, direction)
        if(coordinates.y >= this.map.length || coordinates.y < 0) {
            return
        }
        if(coordinates.x >= this.map[coordinates.y].length || coordinates.x < 0) {
            return
        }
        this.map_tiles[`${coordinates.x}_${coordinates.y}`] = { x: coordinates.x, y: coordinates.y, is_visible: true }
    }

    markAllHidden() {
        Object.keys(this.map_tiles).forEach(function(key) {
            this.map_tiles[key].is_visible = false
        }.bind(this))
    }

    getSlope(tile) {
        return new Fraction((2 * tile.column - 1), (2 * tile.depth))
    }

    getMapXYCoordinates(tile, origin, direction) {
        // UP
        if(direction === 0) {
            return { x: origin.x + tile.column, y: origin.y - tile.depth }
        }
        // RIGHT
        if(direction === 1) {
            return { x: origin.x + tile.depth, y: origin.y + tile.column }
        }
        // DOWN
        if(direction === 2) {
            return { x: origin.x + tile.column, y: origin.y + tile.depth }
        }
        // LEFT
        if(direction === 3) {
            return { x: origin.x - tile.depth, y: origin.y + tile.column }
        }

        return { x: 0, y: 0 }
    }

The getMapXYCoordinates helps translate from the ScanRow to the actual 2D map. The getSlope function returns a Fraction class value for a more accurate slope (rise over run or in this case column/row over depth). The isFloor and isWall is pretty self explanatory. However I did implement doors that close and change their values from “Floor” to “Wall” and vice versa.

The isSymetric function is of note. One of the properties of the shadow casting algorithm is that if tile A can see tile B, then tile B can see tile A. If the math doesn’t work out in one direction for some reason, but does in the other then the two tiles are visible to one another.

Wrap Up

I know the explanation is not all that detailed, this was more of a quick breakdown of the implementation in JavaScript for any other Phaser devs out there.

Again, for a thorough breakdown including some handy visuals, check out the post at albertford.com

Keep getting wiser, stronger, and better.