Recap - Game Board
Part of the Logic & Flow section of Coddy's GDScript journey. Lesson 18 of 78.
Challenge
EasyCheck a game of tic-tac-toe. The program reads three lines, the rows of the board from top to bottom. Each line has three characters: X, O, or . for an empty square.
- Store the board in
board, a 2D array of 3 rows, where each cell is a one-letter string. - A player wins with three of their letter in one row, one column or one of the two diagonals.
- Print one line:
X winsorO wins; if nobody won and the board has no.left,Draw; otherwiseKeep playing.
Every board in the tests has at most one winner. For the input below, the output is O wins, because the middle column holds three O:
XO.
XO.
.OXTry it yourself
extends Node
func _ready():
var board := []
# Read the three rows into board
# Check the rows, the columns and the diagonals, then print the result
pass
All lessons in Logic & Flow
1Strings In Depth
String MethodsSearching in StringsReplace and TrimSplit and JoinRecap - Username Check4Dictionaries Part 2
Nested DictionariesArrays of DictionariesMerging DictionariesCopying DictionariesRecap - Frequency Counter2Advanced Decision Making
Match With VariablesMatch GuardsArray PatternsDictionary PatternsMembership ChecksRecap - Command Parser5Contact Book Application
Display MenuAdd Contact8Student Records Manager
Project OverviewAdd Student3Multi-dimensional Arrays
2D Arrays BasicsAccessing 2D Array ElementsNested Loops with 2D ArraysRecap - 2D ArraysJagged ArraysCommon 2D Array PatternsRecap - Game Board6Sets with Dictionaries
What is a Set?Dictionary as a SetAdding and RemovingUnion and IntersectionSet DifferenceRecap - Remove Duplicates9Advanced Data Aggregation
Summing ValuesFinding Minimum and MaximumCustom SortingRecap - Dictionary SorterPractice on your own: Online GDScript compiler