0
1

[–] ThisIsMyRealName 0 points 1 points (+1|-0) ago  (edited ago)

Since I'm so late the game here, I hope nobody minds my use of code formatting rather than having the code hosted elsewhere. I used Python 3.5 for this solution.

Ask the user what size game board they want to draw

I assume this means prompt for input, but that is not what I did. Argparse is the right way to go for simple one-off user input like the board dimensions, so that is what I used.

import argparse
import sys

def parse_arguments() -> argparse.Namespace:
    parser = argparse.ArgumentParser()
    parser.add_argument('length', type=int,
                        help='number of vertical cells')
    parser.add_argument('width', type=int,
                        help='number of horizontal cells')
    args = parser.parse_args()
    if any(x < 1 for x in (args.length, args.width)):
        print('error: args must be positive integers', file=sys.stderr)
        parser.print_help()
        sys.exit(1)
    return args

def create_board(length: int, width: int) -> str:
    horizontal_line = ''.join(width * ' ---')
    vertical_line = ''.join((width + 1) * '|   ')
    horizontals = length + 1
    board = list()
    while horizontals:
        board.append(horizontal_line)
        horizontals -= 1
        if horizontals:
            board.append(vertical_line)
    return '\r\n'.join(board)

def main() -> None:
    args = parse_arguments()
    board = create_board(args.length, args.width)
    print(board)

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        sys.exit('')

0
1

[–] oddlydrawn 0 points 1 points (+1|-0) ago  (edited ago)

Mine in python3.5. I cheated and looked at Cid's before doing it. I may have also failed at python since mine is longer and more complicated.

Edit 2 days later: Updated mine to draw a go board according to gnugo, prompts user for pluses or not. Sometimes my program exits to shell after selecting the go board without errors. I have no idea why.

0
1

[–] Cid [S] 0 points 1 points (+1|-0) ago 

I like the use of the plus symbols. It really fills things out and makes the boards look much cleaner. It was a good move to do a check to see if they were even needed too.

0
1

[–] Cid [S] 0 points 1 points (+1|-0) ago