Bash Shell Script: Building a Better March Madness Bracket

Finally, you need only call the playbracket function for each of the four regions. You are left with the "Final Four" with the winners of each bracket, but I'll leave the final determination of those contests for you to resolve on your own:


#!/bin/bash
# improved basketball March Madness prediction

function guesswinner {
    ...
}

function playbracket {
    ...
}

playbracket 'Midwest'
playbracket 'East'
playbracket 'West'
playbracket 'South'

Every time you run the script, you will generate a fresh NCAA March Madness basketball bracket. It's entirely random, so each iteration of the bracket will be different. Here's one sample run:


$ ./basketball2.sh

___ Midwest ___

round 1

1 vs 16 : 1
8 vs 9 : 9
5 vs 12 : 12
4 vs 13 : 4
6 vs 11 : 11
3 vs 14 : 3
7 vs 10 : 7
2 vs 15 : 2

round 2

1 vs 9 : 1
12 vs 4 : 4
11 vs 3 : 3
7 vs 2 : 7

round 3

1 vs 4 : 1
3 vs 7 : 7

round 4

1 vs 7 : 1


___ East ___

round 1

1 vs 16 : 16
8 vs 9 : 9
5 vs 12 : 5
4 vs 13 : 13
6 vs 11 : 6
3 vs 14 : 3
7 vs 10 : 10
2 vs 15 : 2

round 2

16 vs 9 : 9
5 vs 13 : 5
6 vs 3 : 3
10 vs 2 : 2

round 3

9 vs 5 : 5
3 vs 2 : 2

round 4

5 vs 2 : 2


___ West ___

round 1

1 vs 16 : 1
8 vs 9 : 8
5 vs 12 : 5
4 vs 13 : 4
6 vs 11 : 6
3 vs 14 : 3
7 vs 10 : 10
2 vs 15 : 15

round 2

1 vs 8 : 8
5 vs 4 : 5
6 vs 3 : 6
10 vs 15 : 10

round 3

8 vs 5 : 8
6 vs 10 : 10

round 4

8 vs 10 : 8


___ South ___

round 1

1 vs 16 : 1
8 vs 9 : 8
5 vs 12 : 5
4 vs 13 : 4
6 vs 11 : 6
3 vs 14 : 3
7 vs 10 : 7
2 vs 15 : 2

round 2

1 vs 8 : 1
5 vs 4 : 4
6 vs 3 : 6
7 vs 2 : 7

round 3

1 vs 4 : 4
6 vs 7 : 6

round 4

4 vs 6 : 4

In this sample run, my script selects team 1 in the Midwest, team 2 in the East, team 8 in the West, and team 4 in the South. More important, note that the rank 16 team won the first round against the rank 1 team in the East bracket. This could not happen in the script I posted last year. My bug is fixed!

The point of using a script to build your NCAA March Madness basket bracket isn't to take away the fun of the game. On the contrary, since I don't have much familiarity with basketball, building my bracket programmatically allows me to participate in the office basketball pool. It's entertaining without requiring much familiarity with sports statistics. My script gives me a reason to follow the games, but without the emotional investment if my bracket doesn't perform well—and that's good enough for me.

______________________

Jim Hall is an advocate for free and open-source software, best known for his work on the FreeDOS Project. He also focuses on the usability of open-source software and has mentored many cycles of GNOME usability testing with Outreachy. Jim is the Chief In