Console Tic-Tac-Toe App (end)

Tram Ho

And here is the complete code of Redirect_User_Concern; helps to add logic that navigates the next step where the User must pause the Double_Threat creation intent to prevent the Computer from winning sooner. We can now remove the Put_Line lines that print the Count_Double_Threats and predictive sets of values.

You can test the previous cases to test the operation of the new logic added to AI_Mockup.Get (Computer_Move, App_State); . On the computer I’m using, the results are pretty good and just a bit unnatural because we haven’t split the potential result sets to do a random selection of possible moves. However, that will require code refactoring for quite some time and you should consider it after you have made sure that the test results are completely fine.

Source Code : GitHub.IO

Although there are still other features that I have not fully learned about the Ada language and the GNAT development environment, this is the right point to end this Sub-Series with the main purpose of learning about the Ada language and the GNAT development environment. Procedural Programming in a development environment designed specifically for this programming paradigm.

Specifically, before we move on to the previously planned Sub-Series Functional Programming , I want to highlight a few features of the Procedural aspect of thinking that have been received by Ada :

  1. Always distinguish very clearly the types of sub-program according to the purpose of use. procedure are used to create side-effect that affect the state data of the external environment. function are used to support local computations and will never produce side-effect like procedure .
  2. procedure are used mainly and function are just add-ons. procedure will play the role of controlling the main operation logic of the program. Utility function are used to minimize the number of local variables for procedure and in places where syntax is required in the form of return-valued expressions, such as contract .
  3. The focus of a program is that the State state data will be created and stored permanently in a global location, or if saved locally, it will be a local variable of important procedure that contribute to the control of the system. control the main processing logic of the program.
  4. Address references to State tuples will be shared among sub-program , and procedure will act as the surrounding objective actions to in turn make changes on the State . To make it easier to imagine, the State will act as Mini Databases during the program’s operation and will be updated and changed many times.
  5. contract binding elements are very helpful for sub-program ; For example, the operation modes of the in , out , in out parameters will help to report an error if we write code that implements inappropriate logic; And other self-defined contract types can be attached to sub-program to ensure the validity of input/output data.

Talking about Ada in particular, the transparency in the language’s syntax and the naming style of elements in the standard libraries also helps me improve my coding habits. However, only the feature of grouping parameters of the same type into lists with semicolons ; in the code declaring sub-program is somewhat redundant. I actually had to re-edit the code so many times just because of the habit from other languages ​​to have a single parameter list with the parameters listed with commas , .

However, that is just the personal opinion of a beginner who is just learning to code. Because perhaps for engineers who program controls for hardware engine like commercial airplanes, perhaps this is a useful feature when designing sub-program with many different parameter groups. .

The only point that I can boldly affirm is that Ada ‘s ability to format the results to print to the Console window is very limited by the strict style design and there is no option for the coder to redefine the parameters. Type'Attribute attribute. When using Integer'Image (Value) with single digit integer values, the result will always be a string with a space character in front. And we also don’t have the feature to use format parameters in C such as %9s to print the result string 9 characters long although the data passed to printf can be much shorter.

If I plan to create another application after this project , I will definitely only use Ada to code the main logic. As for the code to draw the user interface, it will definitely be written in C and import into Ada for later use. And such a combination is probably perfect for both Ada and C ; because Ada is not very popular in general General Purposes application programming, so it will need to communicate with the API of other environments using C ; while C does not have the common data structures like Map , Set , Tree , etc.. and many features support at the language level and high level programming interface such as contract , and also generic in C It is also very difficult to implement.

Now we will move on to the next programming model in the group of popular programming models. Hopefully you still remember Elm ‘s syntax and the basics of Declarative . If you’ve forgotten, take a moment to skim through the previous Sub-Series articles [Declarative Programming + Elm] ; Because the language that we are going to learn and example for the next Sub-Series can be seen as Elm ‘s more complete version of the features supported at the syntax level of the language.

Share the news now

Source : Viblo