I made Othello to teach Python3 to children (1)

Python3 Let's make an Othello game for studying

I started studying Python3 because my self-restraint life has been prolonged and I don't want to spend a gloomy day without doing anything. Python is a language, but applications of that language include stand-alone scripts, cloud services, games, and science and technology calculation. There is a wide range up to .html). For the time being, I would like to learn python while looking back from the basics of the program.

Introduction

This article was written to teach my son, but it seems that Qiita is more responsive than I expected, so there are many people who want to teach the program to their children or who want to study the program more easily. I felt it. Since writing this article, my son has come to express everyday life programmatically. As I write below, the basis of the program is only "behavior, condition, repetition". That's why I programmatically express my mom's anger and begging for pocket money to make me laugh. On the other hand, my son's ambition is big ** "I want to make a game like Fortnite!" **. That's fine, of course, but suddenly having a big goal can be frustrating. This is the same as saying, "You can't understand the English legal terminology dictionary without first studying English." "If you understand the language of Python and the nature of the program, you'll be able to start programming with 3D modeling like Unity, but it's going to be too difficult to get in from Unity." The program I wrote here was made faithfully to this foundation so as not to deviate from "behavior, condition, repetition" as much as possible. So please forgive any code that you feel is redundant. You can modify the source code described here as much as you like and use it as you like. Let's get started.

Simple program

When learning programming, I often wonder whether to learn a language or a library. In many of today's advanced programming development environments, understanding libraries and classes is more important than language itself. In terms of language, if you can understand c, c ++, java, and php, python seems to be a relatively easy language.

By the way, I think the most boring and least useful sample program in studying a programming language is a program called Hello World. There is no sample program that discourages learners so much when studying programs.

So this content doesn't use Hello World. Instead, I would like to make an Othello game.

There are only three basics of the program! ??

No matter what language you use, there are only three basics you need to program.

Basics Description
Action (control statement) Take a step forward
Judgment (conditional statement) Do you hit the wall?
Repeat (loop) Repeat a certain number of times, repeat forever

It looks like this when written like a program. The program will rotate to the right when it hits a wall and will continue until then. Since it repeats forever, it will be a program that will keep walking for the rest of your life. Yes, this is the end of studying the basics of the program.

Repeat forever {
Do you hit the wall?
Yes: Rotate your body to the right
No: Take a step forward
}

The foundation of Python's foundation is indentation

If you want to learn Python, this is the only thing you need to explain in advance.

Python enforces the structuring of a language called indentation. This makes it possible to create programs that are easy to read and do not become redundant as a creator. For Python, indent to indicate that the condition is a block of matching programs. In the following program, if the condition is "year is December 31, 2020", the message "Because it is the end of the year, the next day is January 1, 2021" is displayed, the year is incremented by 1, and the date is set to 1. It is a program to reset.

if year == 2020 and month == 12 and day == 31:
    print("Since it is the end of the year, the next day is January 1, 2021")
    year += 1
    month = 1
    day = 1

If the conditions are matched if you write as below, the message "Because it is the end of the year, the next day will be January 1, 2021" will be displayed, and the year will be +1 regardless of whether it matches or not, and it will be the month. The program will reset the day to 1.

if year == 2020 and month == 12 and day == 31:
    print("Since it is the end of the year, the next day is January 1, 2021")
year += 1
month = 1
day = 1

Let's actually make an Othello game! !!

By the way, I would like to make an Othello game right away, eh? Suddenly? No studying Python? You may think, but the way of studying here starts with learning based on what you have made. Aim to become a Python master while making Othello games! !!

As you all know, the Othello game is a board game in which the winner is the one who takes many positions using white and black pieces in the 8x8 squares.

Once you have created the logic of the Othello game, the program can be transformed into a communication battle game or a game with a good-looking graphic crunch, so here we will first create a simple CUI-based Othello game. Let's.

This time, I will use a development tool called PyCharm for programming. If you do not have it, please download and install PyCharm from the following site.

Download PyCharm from here >> Python IDE --PyCharm

The finished Othello game will be a text-based Othello game like this. It's simple, but it's an Othello game that you can play against each other, so let's make it together! スクリーンショット 2020-05-23 22.19.05.png

I made Othello to teach Python3 to children (2) >>

Recommended Posts

I made Othello to teach Python3 to children (4)
I made Othello to teach Python3 to children (2)
I made Othello to teach Python3 to children (5)
I made Othello to teach Python3 to children (3)
I made Othello to teach Python3 to children (1)
I made Othello to teach Python3 to children (6) Final episode
I made a password generator to teach Python3 to children (bonus) * Completely remade
I made blackjack with python!
I made a Python module to translate comment outs
I made a python text
I made a python library to do rolling rank
I made wordcloud with Python.
I made a package to filter time series with python
I made a Line-bot using Python!
I tried to touch Python (installation)
I made a fortune with Python.
I want to debug with Python
I made a daemon with Python
I made a library to easily read config files with Python
I tried to teach Python to those who have no programming experience
I tried to summarize Python exception handling
I tried to implement PLSA in Python
I tried to implement permutation in Python
I made a payroll program in Python!
I made a character counter with Python
I installed Python 3.5.1 to study machine learning
I tried to implement PLSA in Python 2
I want to use jar from python
I wanted to solve ABC160 with Python
I want to build a Python environment
I want to analyze logs with Python
I tried to implement ADALINE in Python
I wanted to solve ABC159 in Python
I tried to implement PPO in Python
I made a script to display emoji
I made a Hex map with Python
[Python] I tried to calculate TF-IDF steadily
I tried to touch Python (basic syntax)
After studying Python3, I made a Slackbot
I made a roguelike game with Python
What I was addicted to Python autorun
I wanted to solve ABC172 with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
What I did to save Python memory
Othello app (iOS app) made with Python (Kivy)
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
[Python] I made a decorator that doesn't seem to have any use.
I made a tool to automatically browse multiple sites with Selenium (Python)
I made a web application in Python that converts Markdown to HTML
I tried to discriminate a 6-digit number with a number discrimination application made with python
Environment maintenance made with Docker (I want to post-process GrADS in Python
I made a script in python to convert .md files to Scrapbox format
I refactored "I tried to make Othello AI when programming beginners studied python"
I made a function to see the movement of a two-dimensional array (Python)
Updated to Python 2.7.9
I made a python dictionary file for Neocomplete
I want to do Dunnett's test in Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.