Santos 2014
Santos 2014
Abstract—Teaching programming and algorithms is a big easy way to draw and move images on a computer screen
challenge, not only in universities but also in schools and and provides methods and objects that help to create 2D
training centers. Many proposals for stimulating this process games using the Java language.
were made in the last years. Previously to this work we had Previously to this work we proposed a semantic analyzer
developed JPlay. The JPlay framework was proposed and based on behaviors comparison between two programs: a
developed for teaching programming with the development of model program and a student program. We showed results
simple 2D games. In this paper we propose a heuristic based on using a comparison algorithm between the variables of the
the structural analysis of the behaviors of a JPlay program same type of each pair of classes, analyzing its game context
and, based on this heuristic, we developed a tool that makes
instead of syntax details, based on a heuristic for guessing
analyzes of JPlay programs, guiding and teaching a student for
a specific game development. The heuristic consists on a
variables behaviors. The programs compared are simple 2D
comparison approach between the student program and the games developed by JPlay framework. Thus, in order to
model program and it has four levels of analysis: the sequential compare the behaviors of two programs we developed a
code pattern of the JPlay, standardization model, the comparison algorithm between the classes of the model
comparison of similar classes and construction of behavior program and student program, resulting in similar pairs of
trees of similar variables. Thus, the comparison consists on classes. Previously, we show how the algorithm combined
searching behaviors of correspondence between pairs of classes the similar classes of the two programs [15]. In the present
among these programs. In this paper we also present a review paper we will use a four levels heuristic, based on the
of results of BrickBreak game based on the source code of the structural analysis of the behaviors. These levels are: the
integrated high school students in the course of Computers. sequential code pattern of the JPlay, standardization model,
the comparison of similar classes and construction of
Keywords- heuristic; programming; JPLAY; behavior; behavior trees of similar variables. This analysis will show
learning ; games more specifics results using a behaviors comparison
heuristic. Behaviors are identified through the analysis of its
I. INTRODUCTION occurrence scope at the source code, such as an assignment,
a loop or a conditional usage. Therefore, when behaviors
The teaching of programming and algorithms consists in differences are identified, the system makes suggestions
a big challenge, not only in universities but also in schools about these differences found in the student program and
and training centers. Studies point to the difficulty of gives clues that may indicate a possible semantic error. The
teaching and learning the disciplines related to algorithms teacher adds the suggestions in the form of comments in the
and programming, resulting in high dropout rates in source code of the model program, which are automatically
computer courses [13][5]. The main reason for this captured by our solution. In this paper, we will also show
negligence is the difficulty in learning abstract concepts of some results of this comparison.
programming [16] Many proposals for stimulating this
process were made in the last years [3][12][17] [4]. II. RELATED WORK
In this sense, the JPlay framework was proposed and
During the process of learning programming different
developed for teaching programming [9]. JPlay is a
techniques can be used for students in addition of learning to
framework for facilitating the teaching of programming,
program with the purpose of acquiring good programming
providing an algorithmic learning process related with the
practices. The techniques are classified as follows: tests
logic of simple 2D game development. JPlay does not
based programming, programming pattern, automatic
interfere with the structure of basic programming necessary
evaluator, programs diagnostic systems [13].
for a correct learning of algorithmic logic and does not
Based on previous works [7][13], we classify the
introduce specific features of design patterns or stereotypes
techniques related to programming learning context as
of games in the source code. The tool allows the students an
follows: programming based unit testing, proposals of
72
Body class extends the Animation class. Like Sprite, the
Body class also contains methods that can move the image,
and beyond these methods it adds methods to accelerate and
decelerate the image across the screen). The classes
responsible for outputs in the game are: Window (defines a
window where all the game elements will be drawn), Time
(defines a time counter), Sound (defines the sound that will
be played in the game) and Collision (it is a static class, used
to check if there was a collision between two objects. The
occurrence of a collision can be verified using this method in
all classes, or by the Collision static class).
IV. A HEURISTIC BASED ON BEHAVIORS COMPARISON OF
PROGRAMS Figure 1. Stages of the Semantic Analyser Process
We propose in this work a heuristic based on behaviors
comparison of the programs with the aim of analyzing the Finally, all the elements of the game are drawn in the
code being generated by the students. The system is screen. Fig. 2 illustrates the typical sequence of activities of
composed by many stages and modules, which are illustrated the JPlay framework:
in Fig. 1. A main method must be defined in the initialization of
Basically, the systems start classifying tuples of classes the program (1);
x
that are taken from both the model class, which corresponds In the body of the main method objects will be
to the teacher´s program, and student code (1). The analyzer instantiated. One of these objects must contain a
then checks if the pairs of classes are standardized according game loop (infinite loop). Finding a class that
to the properties defined by the teacher for each exercise, contains this loop means finding the loop execution
which corresponds to the model program (2). Thus, in the of the program (2).
x
standardization phase (2), the student´s code must be In the class that contains the game loop (infinite
standardized according to the model program so that they loop) objects are declared (3a). At this point it is
can be compared later. Thus, a markers structure must be possible to check if all objects were also declared
filled in each of the classes of the program model. Each and have been instantiated (3b).
x
marker indicates the characteristics that the class must have Objects declared as Sprites, Animations and
to implement their behavior. The teacher must inform GameImages should be drawn in the window of the
through comments, in the source code of the model program, game; at this point it is necessary to verify if all
the values of the markers in each of the classes of the declared objects of these types were draw (4).
x
program model. Then, the analyzer identifies, in the student An object declared as Window should be updated in
code, the values of the markers of each class. Some of the the game window; at this point it is necessary to
markers that are used are: inheritance, constructor, movex, verify if the Window object is updated. These
movey, keyboard, mouse, method, game object, main and objects must also call their update method (5).
game loop. Although we define basic markers, more specific
markers can be defined by the teacher. If the standardization
is correct for each pair of classes, the analyzer checks for
JPlay sequential pattern (3) and starts the comparison process
(4), classifying variables pairs between pair of classes,
otherwise the analyzer requests the student adaptations in the
code and the process returns to the beginning.
V. JPLAY SEQUENTIAL PATTERN
Our proposal is based on design patterns of sequence
used in JPlay framework. A JPlay sequential pattern is a
code sequence in the program based on JPlay that must
always happen when the program is correct.
JPlay follows a typical game framework pattern: objects,
also called as game objects, are initially defined. A loop is
initiated (also called as a game loop) and each iteration
corresponds to a frame being produced. In this loop all game
objects are updated with their corresponding logic (coming Figure 2. JPlay Sequential Pattern
from an AI algorithm, physic algorithm or even from the
user interface sequence).
73
VI. STANDARDIZATION MODEL
In order to standardize the student´s code in accordance
to the model program, we propose the usage of specific
markers for each class at the model program. The markers
must be declared at the beginning of each class of the model
program. Each marker reports a value of behavior that the
class should follow.
In order to correctly evaluate the class by the analyzer, it
is necessary that the values of its markers are in agreement
with the markers of its class pair in the program model.
Some of the most important markers are:
x Inheritance: Identifies the super class.
x Constructor: The constructor of the class must be
declared.
x Move X: A method to move the object on the x axis
must be declared. The keywords used to find this
behavior are called this.x (attribute used in JPlay) or
movex (method used in JPlay).
x Move Y: A method to move the object on the y axis Figure 3. Examples of markers being applied at the “Ball” class in the
must be declared. The keywords used to find this model program
behavior are called this.y (attribute used in JPlay) or
movey (method used in JPlay).
x Keyboard: Identifies the use of the keyboard in this VII. CLASSES PAIR CLASSIFICATION
class. The keyword used to find this behavior is Our proposal in [15] affirm that since Badros approach
called keydown (method used in JPlay). allows the preservation of the source code and our method
x Mouse: Identifies the use of the mouse in this class. needs a subsequent semantic analysis, we initially convert all
The keyword used to find this behavior is called classes from a developed program into a XML
isleftButtonPressed (method used in JPlay). representation, based on the proposed JavaML method. Due
x Object Game: Identifies instantiated game objects in the increase of tag’s representation from JavaML 2.0, we
this class. ignored this update.
x Main: Identifies a main method in this class. In order to semantically analyze a code under
x Game loop: Identifies an infinite loop in this class. development, the programmer must select in a repository
x Comment: the first comment identifies the general another program which will act as a model program for the
behavior of the class. The others comments are comparison. The analysis consists in compare pairs of
specific and are associated with each marker. Just classes. Every class of the programmer code and from the
below of a marker follows a comment explaining the program base will initially be transformed into XML by the
behavior associated. The comments are used to parser. Each XML file will be read and interpreted by Java
inform the student about the behaviors of the class. language using Document Object Model [8].
The example illustrated on Fig. 3 shows the markers of After defining the pairs of classes, the comparisons
the “Ball” class. According to Fig. 3, the “Ball” class must between pairs are performed. The goal on this stage consists
inherit from Sprite (inheritance), and it has three methods: on identifying the pairs of classes that have higher
the constructor (constructor), a method to move the ball in
similarity. The analysis of similarity between pairs of
the x-axis (moveX) and a method to move the ball in the y-
axis (moveY). classes is based on rules previously established [15]. The
matrix is first initialized with its similarity values,
represented by the “weight” attribute, equal to 0 (zero) in all
its elements. Other attributes are initialized with null.
There are specific rules to find the first and second pair.
In order to classify the first pair of similar classes we
establish as a single rule that the class contains the “main”
method. When it finds two classes containing this method,
the weight value is 2 and the “main” attribute value is true.
After, in order to classify the second pair of similar classes
we establish only one rule: if the class contains the game
loop. When it finds two classes containing the game loop,
the weight value is 2 and the “gameloop” attribute value is
true. The others attributes are calculated according to the
74
rules defined in [15] in order to be performed more analysis
of the student program.
After the first and second pair of similar classes being
classified, the analyzer will take the rest of the classes of the
program to be processed. This classification is performed in
levels. First, the analyzer will search pairs of classes that
extend from the same super class. In Fig. 4, for example, the
“MyBall” class belongs to student program and the “Ball”
class belongs to model program. During the classification the Figure 6. Example of the comparison between “MyBall” and
analyzer verifies that the “MyBall” and “Ball” classes extend “Ball” classes
from the same Sprite class. The analyzer verifies the list of
variables of each one of the classes of the program that
extend the same super class. In Fig. 5, for example, the VIII. VARIABLES PAIRS CLASSIFICATION AND
“MyBall” and the “MyBar” class belong to the student COMPARISON OF BEHAVIOR TREES
program and extend Sprite class, the “Ball” and “Bar” class After defining all pairs of similar classes, variables of the
belong to model program and also extend Sprite class. Then, same type in each of the classes of the pair should be
all the combinations between these classes of the two compared according to their behavior and then pairs of
programs will be analyzed with the goal of finding the pairs variables should be classified. The algorithm compares the
of classes more similar. In this step the combinations are variables of the same type using a list of behaviors and then
performed by comparing the lists of variables of each class the pair containing the smallest weight is rated as the most
from the programs, as shown in Fig. 6. Each variable list similar pair of variables.
contains the variable type and the number of variables of After that, similar pairs of variables are defined and
each type. The algorithm compares each pair of lists and then analyzed. In order to compare these variables, we
calculates the difference between the values of variables of propose a tree structure, called behavior tree. This structure
same type, after the similarity weight assigned the value of contains all the behaviors of a variable, which in our case we
the sum of the results. Then, the pair having the lowest defined as 3 possible types:
weight is rated as the most similar pair. Generally the x Assignment: It is identified when happens an
comparison between the lists of variables each class does not assignment statement in the class;
get full precision. Thus, the results may be close to reality,
x Conditional: It is identified when happens a
but not entirely correct. In order to obtain greater accuracy in
conditional command in the class;
the result, the algorithm performs a second comparison based
on lists of behaviors. At the next comparison, the algorithm x Loop: It is identified when happens a loop command
generates lists of behaviors containing the type of behavior in the class.
and the value of that type of behavior. The algorithm The example of the Fig. 7 shows an assignment behavior
compares each pair of lists again and then the pair containing of the “left” variable in the constructor of the “Ball” class.
the smallest weight is classified as most similar pair. At this We build a behaviors tree to each variable, and the
level, all pairs of similar classes are defined, and the pairs analyzer compares the behavior tree of a variable of a class
classified should be compared. that belongs to the student program with the behavior tree of
its similar variable from model program. The behavioral
trees of both the variables are compared and when behaviors
differences occur it is possible that the student program has
an error.
Figure 5. Example of classes from student program and model In this point, when behaviors differences are identified in
program that will be combined the trees, the analyzer makes suggestions about these
behaviors differences found in the student program and give
clues that may indicate a possible semantic error. The
75
suggestions are defined as comments in the source code of In this example, one more assignment behavior in the
the program model. Each comment must be previously student program does not necessarily change the behavior of
edited predicting possible suggestions to the student. For “MyBall” class, depending on the value that was assigned to
example, in Fig. 7, if the assignment behavior is not "carry2" variable, so the analyzer does not have to give a
identified in the behavior tree of the similar variable in the totally accurate result for an inappropriate behavior in
student program, the following comment associated with the “MyBall” class of student program but it can give a
behavior will be captured and suggested to the student: suggestion closer to the truth based on the difference found
x “In the class constructor, initialize the attribute that by comparing the trees.
controls the initial movement of the ball to the left or
right.” IX. RESULTS
The example in Fig. 8 shows the behaviors tree of the In this paper we propose a novel heuristic that checks a
“left” variable in the “Ball” class of the model program. The JAVA code and guide a student for a specific game
example in Fig. 9 shows the behavior tree of the similar development, giving clues of possible semantic failures,
“carry2” variable of the student program, where in this case within a game oriented framework.
it is found a difference (one more assignment behavior). We developed a validation scenario in a classroom with
Since the analyzer found a difference in the assignment 10 students of the integrated high school of the Informatics
behavior at the comparison between the behaviors trees of course. The students were proposed to develop a
the "left" and "carry2" variables, thus all comments related to “BrickBreak” game, using JPlay framework. In this paper,
the assignment behavior in the model program will be we analyzed the “Ball” and “Bar” classes of the 10 codes
suggested to the student: developed, based on the model program developed by the
x “In the class constructor, initialize the attribute that teacher. The results analysis presented here are related with
controls the initial movement of the ball to the left or two levels of analysis (according to Fig. 1): Checking for
right.” standardization between programs (2) and Comparison of the
behavior trees (5).
x “Modify the movement of the ball if the ball position We evaluated the results according to behaviors expected
at the X axis is less than minimum limit of the game for each class. The “Ball” class has two basic specifications:
window and it is going to the left.” it must move in the x and y axis and collide with objects (bar
x “Modify the movement of the ball if the ball position and block). The “Bar” class also has two specifications: it
in the X axis is greater than maximum limit of the should move through the keyboard control, for both right and
game window and it is going to the right. Consider the left sides and collide with the ball.
this case the width of the ball. Example: maximum In case of the standardization model the results were
limit - width of the ball.” marked as positive when the analyzer does not detect
differences between the student program and the
standardization model and negative when the analyzer
detects differences between them.
For the behavioral trees, we evaluated the results as false-
positive when the analyzer does not detected differences, but
the behavior of the object is not correct and false-negative
when the analyzer detects differences but the behavior of the
object is correct. It is considered, negative when the analyzer
detects differences that really it exists and positive when the
analyzer does not detect differences and the behavior of
object is correct.
Figure 8. Example of the behaviors tree of the variable “left” in the “Ball” Table I summarizes the results for the evaluation strategy
class of model program
for the “Ball” class example.
Students 1 and 4 used one method more than requested in
the standardization of model. The analyzer checks the
difference between the students program and standardization
model and prints the following suggestion for the student:
76
Evaluation for the Ball class the program is not according to the standardization and it is
Status
Analysis according not possible compare variables, form pair of variables and
Student with the Comparison of
program compare the behaviors trees. Thus all the comments relating
standardization behavior trees
between programs
to behaviors of the “Ball” class are suggested to the student.
model)
TABLE II. TABLE COMPARISON BETWEEN “MOVEX” (STUDENT 1)
AND “LEFT” (MODEL PROGRAM) VARIABLES
2 Correct Positive Positive
Comparison between “movex” (student 1) and “left” (model
3 Correct Positive False-negative
program) variables
Incorrect Number of
Type of
(with the Number of behaviors behaviors in
4 Negative False-negative Behavior Difference
standard in “movex” variable “left”
model) variable
5 Correct Positive False-negative Assignment 5 3 2
77
pair of variables and compare the behaviors trees. Then the X. CONCLUSION
following comments are shown as suggestions: This paper presents a novel heuristic strategy based in an
x “Define the movement of the bar to the right through analyzer that interpreting semantically a JPlay code, guide a
the use of the keyboard using the KeyDown() student for a specific game development process. Although
method. Check which is, in the game window, the our implementations and tests are related to JPlay
maximum value of the right margin.” framework, our proposal can easily be adapted to other
x “Increase the movement of the bar on the x axis, program patterns.
making the bar moves to the right.” The goals of the analyzer are to interpret semantically a
Java program that uses JPlay and return results of this
x “Define the movement of the bar to the left through analysis to the student. Our proposal brings significant
the use of the keyboard using the KeyDown() contributions to researchers working in the field of
method. Check which is, in the game window, the programming education and software engineering, having as
minimum value of the left margin.” main contributions the architecture for classification of
x similar classes and the definition of the data structure
“Decrement the movement of the bar on the x axis,
(behavior tree) starting from the behaviors of variables. Our
making the bar move to the left.”
paper also contributes in the sense that introduces a tool able
TABLE IV. TABLE EVALUATION FOR THE BAR CLASS
to semantically interpret code built by students, returning
results, pointing out problems and suggesting solutions.
Evaluation for Bar class As future work we intend to develop a tutoring interface
Analysis according in order to manage the results received by the analyzer and
Student Status with the Comparison of
program standardization behavior trees
the communication with the student. Also, as future work,
between programs we intend to improve the efficiency of the algorithm using
Incorrect classification approaches.
(with the
1 Negative False-negative
standard REFERENCES
model)
[1] A. Adam and J. Laurent, “LAURA, a system to debug student
Incorrect programs”, artificial intelligence, v.15, n.1, pp. 75-122, 1980.
(with the
2 Negative False-negative [2] V. de A Alexis. and J. F. Deller, “Aplicando Padrões de Seleção no
standard
model) Ensino de Programação de Computadores para Estudantes do
Incorrect Primeiro Ano do Ensino Médio Integrado”. In X Encontro Anual de
(with the Computação – EnAComp, 2013.
standard [3] E. Allen, R. Cartwright and B. Stoler, “Drjava: a lightweight
3 model Negative Negative pedagogic environment for java”. SIGCSE Bull., 34(1):137-141,
and with 2002
the [4] A. Allowatt and S. Edwards, “Ide support for test-driven development
behavior) and automated grading in both java and c++”. In eclipse “05:
Incorrect Proceedings of the 2005 OOPSLA workshop on Eclipse technology
(with the eXchange, pages 100-104, New York, NY, USA. ACM Press. 2005.
4 Negative False-negative
standard [5] L. S. Barbosa, T.C.B. Fernandes and A. M. C. Campos, “Takkou:
model) Uma Ferramenta Proposta ao Ensino de Algoritmos”. In: XXXI
Incorrect CONGRESSO DA SOCIEDADE BRASILEIRA DE
(with the COMPUTAÇÃO - WEI XIX WORKSHOP SOBRE EDUCAÇÃO
5 Negative False-negative
standard EM COMPUTAÇÃO, 2011, Natal. WEI XIX WORKSHOP SOBRE
model) EDUCAÇÃO EM COMPUTAÇÃO, 2011.
Incorrect [6] C. A. Botelho, “Sistemas Tutores no domínio da programação”.
(with the Revista de Informática Aplicada/Journal of Applied Computing, v.4,
6 Negative False-negative
standard n. 1, 2010.
model)
[7] K. V. Delgado, “Diagnóstico baseado em modelos num sistema
Incorrect
inteligente para programação com padrões pedagógicos”. Master's
(with the dissertation, Institute of Mathematics and Statistics. 2005.
7 Negative False-negative
standard
model) [8] DOM, available in http://www.w3.org/DOM/. Accessed in November
Incorrect 2012.
(with the [9] B. Feijó, E. Clua, F.S.C. da Silva, Introdução à Ciência da
8 Negative False-negative Computação com Jogos: Aprendendo a Programar com
standard
model) Entretenimento. Campos Elsevier.1º ed. 2010.
9 Incorrect Negative Negative [10] W. L. Johnson,E. Soloway, “Proust: Knowledge-based program
understanding”. In ICSE 84: Proceedings of the 7th international
10 Incorrect Negative Negative conference on Software engineering, pp. 369-380, Piscataway, NJ,
USA, 1984. IEEE Press.
[11] JPLAY, available in http://www.ic.uff.br/jplay/. Accessed in April
2012.
78
[12] M. Kolling, B. Quig, A. Pattern, and J. Rosenberg, “The BlueJ system Education”. In SEKE 2013: Proceedings of the twenty-fifth
and its pedagogy”. Journal of Computer Science Education, Special International Conference on Software Engineering & Knoledge
issue on Learning and Teaching Object Technology, 13(4):249- Engineering, pp-668-673, Boston, June 27-29, 2013.
268,2003. [16] N.S.R.S. Santos, C.E. Rapkiewicz, “Ensinando princípios básicos de
[13] W.R. Pinheiro, L.N. Barros,F. Kon, “AAAP: Ambiente de Apoio ao programação utilizando jogos educativos em um programa de
Aprendizado de Programação”. In Workshop de Ambientes de Apoio inclusão digital”. In: SBGAMES - VI Simpósio Brasileiro de Jogos
à Aprendizagem de Algoritmos e Programação, São Paulo, 2007. para Computador e Entretenimento Digital, 2007, São Leopoldo - RS.
[14] C. E. Rapkiewicz et al., "Estratégicas pedagógicas no ensino de [17] H. Traetteberg, T. Aalberg, “Jexercise: a specification-based and test-
algoritmos e programação associadas ao uso de jogos educacionais". driven exercise support plugin for eclipse”. In eclipse “06:Proeedings
RENOTE, v.4, n.2, 2006. of 2006 OOPSLA workshop on eclipse technology eXchange, pages
[15] E.C.O. Santos, G.B. Batista, E.W.G. Clua, “A Knowledge Modeling 70-74, New York, NY, USA. ACM Press. 2006.
System for Semantic Analysis of Games Applied to Programming
.
79