Java 20 About The System Development Process B08T7KWRV3
Java 20 About The System Development Process B08T7KWRV3
CONTENTS
Foreword 6
1 Introduction 8
3 Test-Driven Development 32
4 Design patterns 40
�e Graduate Programme
for Engineers and Geoscientists
www.discovermitas.com�e Graduate Programme
for
Engineers and GeoscientistsI wanted real responsibili� Maersk.com/Mitas
Real work InternationaalInternational opportunities
6 Poker 47
6.1 Vision 47
6.2 Analysis of poker 48
6.3 The process 57
6.4 Iteration 1 60
6.5 Iteration 2 64
6.6 Iteration 3 80
6.7 Iteration 4 89
6.8 Iteration 5 97
6.9 Iteration 6 100
6.10 Iteration 7 102
6.11 Iteration 8 104
6.12 Iteration 9 108
FOREWORD
It is the last book in this series of books on software development in Java.
The book deals with system development focusing on the process and
primarily in relation to major system development projects. In addition, the
book gives an introduction to three concrete system development methods:
Unified Process, SCRUM and Extreme Programming. In addition, a number
of other activities and techniques are described that are part of modern
system development, regardless of whether one uses a method. After you
have read these 20 books on system development in Java and solved all the
exercises and tasks, you may not be able to call you a professional Java
developer. This can only lead to by experience, but you have a good
foundation and you are well-dressed to join a professional team of software
developers. You never graduate as a software developer, and there are
always new versions of products and methods that you have to learn, but I
hope these books can provide a good basis. Everything is not included either
because there was no room or because it was forgotten and something else
might even be deprecated, but maybe a future release may remedy some of
it, but if it happens, I will end up at the same place, where something did not
come along and something else is deprecated. Software development does
never stop.
As the title says this series of books deals with software development, and
the goal is to teach the reader how to develop applications in Java. It can be
learned by reading about the subject and by studying complete sample
programs, but most importantly by yourself to do it and write your own
programs from scratch. Therefore, an important part of the books is
exercises and problems, where the reader has to write programs that
correspond to the substance being treated in the books. All books in the
series is built around the same skeleton and will consist of text and examples
and exercises and problems that are placed in the text where they naturally
belongs. The difference between exercises and problems is that the exercises
largely deals with repetitions of the substance that is presented in the text,
and furthermore it is relatively accurately described what to do. Problems are
in turn more loosely described, and are typically a little bigger and there is
rarely any clear best solution. These are books to be read from start to finish,
but the many code examples, including exercises and problems plays a
central role, and it is important that the reader predict in detail studying the
code to the many examples and also solves the exercises and problems or
possibly just studying the recommended solutions.
All books ends with one or two larger sample programs, which focus
primarily is on process and an explanation of how the program is written. On
the other hand appears the code only to a limited extent – if at all – and the
reader should instead study the finished program code perhaps while testing
the program. In addition to show the development of programs that are
larger than the examples, which otherwise is presented, the aim of the
concluding examples also is to show program examples from varying fields
of application. Most books also ends with an appendix dealing with a subject
that would not be treated in the books. It may be issues on the installation of
software or other topics in computer technology, which are not about
software development, but where it is necessary to have an introductory
knowledge. If the reader already is familiar with the subject, the current
appendix can be skipped.
The programming language is, as mentioned Java, and besides the books use
the following products:
It is products that are free of charge and free to install, and there is even talk
about products, where the installation is progressing all by itself and without
major efforts and challenges. In addition, there are on the web detailed
installation instructions for all the three products. The products are available
on Windows and Linux, and it therefore plays no special role if you use
Linux or Windows.
All sample programs are developed and tested on machines running Linux.
In fact, it plays no major role, as both Java and other products work in
exactly the same way whether the platform is one or the other. Some places
will be in the books where you could see that the platform is Linux, and this
applies primarily commands that concerning the file system. Otherwise it
has no meaning to the reader that the programs are developed on a Linux
machine, and they can immediately also run under Windows unless a
program refers to the file system where it may be necessary to change the
name of a file.
Finally a little about what the books are not. It is not “how to write” or for
that matter reference manuals in Java, but it is as the title says books on
software development. It is my hope that the reader when reading the books
and through the many examples can find inspiration for how to write good
programs, but also can be used as a source collection with a number of
examples of solutions to concrete everyday programming problems that you
regularly face as a software developer.
1 INTRODUCTION
All the previous books in this series have been about system development
and how to write programs using the Java programming language, and if I
look backwards it’s probably the last that fills most, and it’s actually not fair
because if you’re are going to be a good software developer, you should
strive to free yourself from the tools and instead focus on the methods and
principles common to all system development tasks. However, it is not so
easy, because in the end, one must necessarily become concrete and learn
how to work with the technologies and tools needed to implement solutions
practices. In fact, it is a bit of a dilemma in software development, where
you have always been emphasized the importance of learning good system
development methods and focusing on analysis, design and patterns, and
where the technology and programming in some language was secondary. As
mentioned above, the intentions of this series of books were to write about
software development, but with the emphasis on the process, and perhaps the
final examples should have been more important than the case is. Much of
the foregoing has focused on Java and details, but maybe it does not matter,
because that’s what it’s all about.
We have gradually developed software for over 50 years, and during that
time many new programming languages have been developed, many
different development tools, and several system development methods and
other guidelines for developing a program has also been developed, so in
principle, it should be easier to develop a program today than before. It’s
also – you simply have better tools than before, but conversely, the programs
you are developing today are often much bigger and more complex than
before, and also they have a greater diversity. For example, there is a big
difference in writing a PC application and a web application, and again it is
different to write an app to a mobile phone. In particular, the last means that
it’s hard to be good all the way around and that it is necessary to specialize
as software developer. Finally, new tools (including programming
languages) are constantly being marketed to address specific tasks, so there
are always new tools to be used to and use in the daily work as a
professional software developer.
The primary tool in these books has been Java and NetBeans, but there are
actually many other tools that relate to the Java world, and all have the same
purpose to streamline the software development process. Among other
things, I have previously mentioned alternatives to NetBeans (Eclipse is an
example), while others can interfere with NetBeans. Many of these tools are
good and are widely used in practice, but although there is no room for a
presentation in these books, I will mention actual project management tools.
There are many each with their advantage, but they are tools that support the
implementation of large projects with many project participants. They have
facilities to manage large projects where multiple developers work closely
together, including controlling versions, so that you can always go back to a
previous version, so some developers will not override others’ code without
being sure that you can recreate the code. It’s comprehensive tools, that it
takes time to learn to use, and partly are either or tools. These are tools that
are implemented on the basis of a decision in the development organization
and after extensive investigations, which all have to undertake and apply. On
the other hand, they are tools used by all major development organizations,
and thus tools that you will certainly meet, and it is a must in the
development of large and complex IT solutions.
1. Unified Process
2. SCRUM
3. Extreme programming
You can say that you actually work without using a method, and it is
contrary to everything that has been said and written about system
development, but yet the method is widespread, and under certain
assumptions it also gives good opinion in practice.
Of course, you can not tackle the code and test process before you
understand what it is for a program to be written, and the process therefore
starts with a form of analysis where you can clarify the requirements of the
program with the customer. Then you start programming and testing whether
the code you have written works according to the requirements, and so
proceed with a large number of small steps until the task is solved.
In order for such a simple approach to lead to a successful outcome, there
are two prerequisites that must be met:
If these prerequisites are present, there is nothing to solve the task after a
code and test model, and in reality there may not be much else that makes
sense. Here it is important to note that in the real world there are many tasks
that just meet the above two assumptions, so code and test programming has
its uses and has been used far more frequently than the many books on
system development prescribe.
I will not go into the content of the method and just refer to the book Java 7,
but for smaller and well-defined tasks, the method is still interesting and can
be used very well. Several have tried to improve the method, primarily by
incorporating ideas from other system development methods and one version
of the waterfall model can be found in the literature described as the
waterfall model with feedback, which is an attempt to formally integrate
iterative system development into the waterfall model, what it in the
principle does not support. Whatever you do, the waterfall model for large
complex IT systems will never be the right system development method.
Here, instead, you have to use one of the agile system development methods
described below.
1. Inception
2. Elaboration
3. Construction
4. Transition
One has the greatest success with unified process as a method for larger
projects, where the task is relatively well-defined and where the project is
associated with more developers. In many ways, the method can be seen as
an alternative to the waterfall model, recognizing that this method is not
suitable for the development of large and complex IT solutions. It is an
iterative method in which the task is solved through a number of iterations,
and one can reasonably perceive each iteration as the partial solution
implemented after the waterfall method.
www.job.oticon.dk
The unified process is also an agile system development method, and thus a
method where the goal is quickly to deliver value solutions for the customer,
and at the same time after customer’s testing of the delivered sub-solutions,
it can easily and accurately adjust the requirements according to the
customer’s wishes. All modern systems development methods today are call
agile, and it is perhaps not much more than an observation that today’s IT
systems are far larger and more complex than before.
Inception
This phase will usually consist only of a single iteration. It is a start-up phase
where you must analyze what it is for a task to be solved. It is not the goal to
prepare a completed requirement specification, but inception is a short phase
in which you analyze critical requirements and determine the basic visions
of the system. You should not try to make a detailed list of as many system
requirements as possible. A risk analysis for the development of the system
must be carried out and a decision must be made whether or not to complete
the project. The objective is:
The first phase is a clearing phase and is a short phase and is typically
performed as a single iteration. How long does of course depend entirely on
the specific task, and maybe the phase lasts only a few days, and I find it
hard to imagine an inception phase that spans more than a few weeks.
During the start, the project team must clarify the following:
- A task formulation
- A requirement specification
- One or more prototypes
- Attachments
- Conclusion
Elaboration
In this phase, one or more iterations are performed (and usually there will be
more and maybe many), in which it will develop a part of the overall system
in an iteration. One can thus think of an iteration as a mini development
project, and the result will basically be a program (a product) that the task
manager can test. One can think of an iteration as a development process that
brings the entire project from one state to another.
An iteration should take shortly in time, but vice versa, it should also be so
extensive that the customer experiences progress. An iteration length is
determined of the current
WHY WAIT
PROGRESS?
DARE TO DISCOVER
Discovery means many different things at
Schlumberger. But it’s the spirit that unites every
single one of us. It doesn’t matter whether they
join our business, engineering or technology teams,
our trainees push boundaries, break new ground
and deliver the exceptional. If that excites you,
then we want to hear from you.
careers.slb.com/recentgraduates
FOR
project, but the time frame will typically be from 2 to a few weeks. Of
course, the number of iterations will also be determined by the scope of the
project, and in small projects, there will in principle only be a single
iteration, but if you use a unified process, there will usually be more.
1. analysis
2. design
3. programming
4. test
- The project is in a stable state, which can be presented to the task manager
or customer. It will usually be a software product that the task testers can test
and comment on.
- An updated version of the task formulation with regard to decisions taken
in connection with the implementation of this iteration, as well as an
extension of a section with important results for the current iteration.
- An updated version of requirement specification based on the analysis
performed during the iteration.
- A conclusion that includes the customer’s remarks after testing the product
and the developers’ recommendations regarding the continued system
development.
- Adjustment of project plan, including planning of next or the few next
iterations.
Looking at the above, it may seem that you work without having a schedule
and decides what should happen as you move forward in the project. Such,
of course, you can not develop IT systems, because the task manager or
customer must know when the system is expected to be delivered and what it
will cost, but vice versa, it should be noted that when unified process
continuously adjusts the requirements and continuously plans iterations, it is
exactly, what’s means that it’s an agile method. This does not mean that you
are working without planning, but it is a recognition that for large and
complex systems it is impossible to describe a completed requirement
specification and estimate how long the development will take and what it
will cost, and the question is, what you then can do it. The idea of unified
process is that you continuously work through the requirements specification
and the project plan so that after the completion of elaboration, the
requirements specification is complete and including the final price for what
the solutions cost and when it can be delivered and applied. Until then, it
must all be based on estimates that are continually underpinned and adjusted,
and that is exactly the dilemma of system development. However, in the
unified process, the goal is that after elaboration the requirements must be in
place, as well as the completed project plan and project requirements for
resources.
As an addition to the above, I would like to mention that when it is so
difficult to estimate a system development project, it is not only because
developers are bad planners, but equally because the task manager and
customers of large and complex IT solutions can not formulate the task. It
requires a process of continuously identifying the requirements and deciding
what to do, and what should be delineated, and remember that delineation
may also be postponed to later. This is exactly the process that elaboration
deals with.
1. plan what the iteration should include 2. and when the iteration must be
completed
With regard to the first, the iteration must include a well-defined work of the
entire project process, and the iteration should typically end in a month and
should rarely last much longer. More people may work on the same iteration,
but there will be few. Another question is what should happen if the iteration
is not completed on time. Here it is an imperative requirement in unified
process that the iteration is to be terminated on time, and what may be
missing has to be postponed to a later iteration.
Construction
One can also think of construction as a phase, where the project has now
moved into a stable and planned course, through which the project moves
forward towards the finished product through a carefully planned course. At
that point, the risk is gone and there is only “hard” work left.
The last phase is also an iterative phase, but typically there are few iterations
and often only one. It is the delivery phase and the tasks can vary a lot, but
are the same as I previously described in the book Java 7. The planning of
the phase’s iterations takes place during elaboration.
2.4 SCRUM
Now SCRUM is not always the right method, and for SCRUM to makes
sense, the project must be of a reasonable size and be a project that should
solved by a team of developers. In addition, it usually has to be a project
characterized by many uncertainties and complexity, and where there is a
need for agile methods, but can a project to some extent be characterized in
that way, SCRUM has proven itself as an effective project management
method.
where you can think of the first one as planning and the other as production,
but how far the largest part of time is used in the final phase. In fact, phases
are not the right word, as it is not so that you are either in one phase or
another, but it all starts with pre-sprints, after which you perform a series of
sprints and eventually (and often) return to the pre-sprints phase. You
usually outline the SCRUM with a figure similar to the following:
During pre-sprint, one focuses on injecting the user requirements and
describing them as tasks to be solved. These descriptions are called stories.
The result will typically be a large collection of stories, called Product
Backlog. Typically, you do not complete Product Backlog before starting the
individual sprints, and as soon as you find that enough information has been
gathered that some stories are well described, you can start the first sprints.
The goal is to get something done that end users can relate to and evaluate,
and then to return to the pre-sprint phase and possibly update Product
Backlog.
Looking at the sprints phase, it includes a sprint planing for every sprint, a
meeting where you plan what stories from Product Backlog to be transferred
to Sprint Backlog, and thus what stories to work on in it a following sprint.
A sprint is scheduled to take a certain period of time, which may vary, but
typically takes a sprint of about 4 weeks, and it is recommended that a sprint
should not take longer than one month. The team breaks down the selected
stories for tasks that are then delegated among the team’s members. During a
sprint, daily meetings, called Daily Scrum, are held, where each team
member reports briefly the progress (or the opposite) in connection with the
current tasks. These Daily Scrums are short meetings, and may take up to 15
minutes. At the end of a sprint, a meeting called Sprint Demo (or Sprint
Review) is held. This meeting is held together with the task manager, where
the team demonstrates the result of the current sprint and thus how the
individual
RIGHT TRACK
Give your career a head start
by studying with us. Experience the advantages of our collaboration with
major companies like ABB, Volvo and Ericsson!
stories are resolved. The entire sprint finishes with a Scrum Retrospective,
that is a meeting that is a review of the sprint, where the team looks back on
the course for improvements.
In connection with a SCRUM project, there are three roles (and there may be
no other roles), and these roles are completed by the scrum team:
1. Product Owner, which is one person who is part of the project on full-
time or on part-time, and which represents the business area within the
project is anchored.
2. Scrum Master, who is one person who is full-time or on part-time on the
project and who is a coach and facilitator for the development team.
3. The Development Team, which is 3–9 full-time employees (also called
specialists) and is part of the development organization as those who
perform the individual sprints.
1. The team is self-organizing and plans its work without explicit leadership
from the outside. One or more people in the team can be in charge of
management while other participants are solely responsible for special
specialist activities, but in SCRUM there is no division of management and
specialist functions.
2. The team participants have all the necessary expertise and competencies
needed to get the task solved and without the need to get help from outside.
The Product Owner
Any project needs a person familiar with the business area whose task is to
maximize the value of the team’s work and it is this person that is called
Product Owner. Generally, the person comes from the development
organization. It is important to be aware that the Product Owner must be
know the problem area, but the person does not need to have special
knowledge about system development. It is the Product Owner that is
responsible for the project’s Product Backlog, which is a priority list of
stories to be solved and it is the central planning tool in SCRUM. Stories are
prioritized in terms of their value for the user organization, so that high-
quality stories are solved first. It is also the Product Owner who is
responsible for that each user story being easy to understand for the Scrum
Team and other stakeholders.
It is Product Owner who communicates with the task owner and user
organization and uses this information to update the project’s Product
Backlog. It is also the Product Owner who has an overview of the progress
in the project and keeps the project stakeholders updated with regard to the
final end date.
Scrum Master
Scrum Master ’s task is to assist the Scrum Team by coaching them and
ensuring that all principles of SCRUM are respected. Scrum Master must
therefore have in-depth knowledge of SCRUM and the principles of the
method. It is a management function, but it is not a project manager. Scrum
Master will lead the SCRUM process, but not the Scrum Team. In addition
to ensuring that the Development Team understands and uses SCRUM
correctly, it is also the Scrum Master’s task to remove obstacles to the
Development Team, ease everyday life and generally coach the participants.
Scrum Master must also support Product Owner to pass the right information
to the project’s stakeholders and generally provide expert knowledge
available to the Product Owner.
It is allowed for a person to be both Scrum Master and a member of the
Development Team, but it is not recommended.
The Development Team
Members of the Development Team are IT experts and are responsible for
delivering solutions to the elements of the backlog. Members generally have
knowledge to do everything from A to Z in connection with the development
of a task from the backlog, and they must be able to work independently
themselves, and be able to solve the challenges that arise. One assignment
can be awarded to a particular member through a sprint, but the entire
Development Team is responsible and accountable for the task and there is
thus no single person who owns a particular task.
The Development Team delivers the finished product developed through an
iterative process managed by the project’s Product Backlog. It is highly
recommended that team members work full-time on the current project, and
efforts should be made that the Development Team members not being
replaced along the way, as it is considered important to ensure that members
are focused and agile.
www.schaeffler.com/careers
The sprints
Then there is the content of the individual sprints, where the actual system
development takes place. A system development project managed by
SCRUM solves the task through a number of iterations, called sprints, where
a sprint is time-boxed and takes a certain period of time. A sprint contains 4
activities:
1. Sprint Planning is the first activity in a sprint, where the Scrum Team
plans what will be the result of the sprint and what to deliver.
2. Daily Scrum. The Development Team starts the work immediately after
Sprint Planning is completed. During the sprint, the Development Team
keeps daily meetings, called Daily Scrum. It is a short meeting of
approximate 15 minutes where the work for the next 24 hours is coordinated.
As part of SCRUM it is recommended that these meetings be held standing.
3. Sprint Review. Before the sprint finishes, the Development Team presents
the sprint’s results for the user organization and retrieves feedback.
4. Sprint Retrospective. After Sprint Review and as the last in the sprint, the
Development Team holds an internal meeting as a kind of review of the
sprint in order to learn from the course.
Sprint Planing
Then, a Sprint Goal is written, which is nothing else a short text describing
the target of the current sprint, including what are the criteria for the sprint to
finishing and what the tasks are solved. Sprint Goal must also contain at
least a detailed plan for the first days of the sprint. Sprint Goal is part of
Sprint Backlog, and there are no special requirements for documentation or
form, and often a board is used, which makes it easy to maintain the plan,
and ensure that the plan is visible to everyone. Sprint Backlog is thus made
up of
1. Sprint Goal
2. The stories selected from Product Backlog for the current sprint.
3. A detailed work plan for the sprint, where the tasks (stories) can be
categorized as To Do, Doing or Done.
In principle, a sprint can not be interrupted, but Product Owner may, as a
sole exception, decide to interrupt a sprint typically caused by
events/changes in the project’s environments/ prerequisites.
Daily Scrum
As its name says, it is a daily meeting held throughout the sprint period. At
the meeting, only members of the development team participates. The
meeting lasts no more than 15 minutes, and at this meeting each team
participant must answer three questions:
Team members must compare the progress with the Sprint Goal, but should
also estimate the likelihood that a task will be completed before the sprint is
complete.
Sprint review
It is a meeting to be held at the end of a sprint and the meeting will take for a
sprint of 4 weeks max 4 hours, but for a shorter sprint the meeting will
usually be shorter. The meeting includes the entire Scrum team but also
other stakeholders, and at the meeting the solution of all tasks from the
current sprint are presented. The goal is to get feedback and as early as
possible to adjust the requirements so Product Owner can update the
project’s Product Backlog.
It is the Development Team that presents the product, but only for tasks that
are Done and not for tasks that are “almost” Done. It is the Product Owner
who before the meeting must ensure that the products presented also are
Done.
At the end of the whole sprint, another meeting called Sprint Retrospective
is held, which is a meeting of 2–3 hours. It is a meeting where you look back
on the sprint for improvements, and it applies to both the working
procedures for the individual team participants, processes and the tools that
you use.
678'<)25<2850$67(5©6'(*5((
&KDOPHUV8QLYHUVLW\RI7HFKQRORJ\FRQGXFWVUHVHDUFK
DQGHGXFDWLRQLQHQJLQHHU
LQJDQGQDWXUDOVFLHQFHVDUFKLWHFWXUHWHFKQRORJ\U
HODWHGPDWKHPDWLFDOVFLHQFHV
DQGQDXWLFDOVFLHQFHV%HKLQGDOOWKDW&KDOPHUVDFF
RPSOLVKHVWKHDLPSHUVLVWV
IRUFRQWULEXWLQJWRDVXVWDLQDEOHIXWXUH¤ERWKQDWL
RQDOO\DQGJOREDOO\
9LVLWXVRQ&KDOPHUVVHRU1H[W6WRS&KDOPHUVRQIDFHER
RN
More about
SCRUM
An activity that in principle always takes place in parallel with the individual
sprints is called Product Backlog Grooming. It is always about reviewing
and adjusting items in Product Backlog, and typically includes adding
details, adjusting estimates, and so on. It is Product Owner who is
responsible for prioritizing the items in Product Backlog, and it is the
Development Team that is responsible for estimating the items.
Although it is not part of SCRUM, it is recommended that you plan a day off
or two between each sprint, which you can use to read articles, attend
courses or workshops or otherwise orientate yourself to new subjects, or you
can simply go for a walk and enjoy the nature. Perhaps this idea may be
difficult to sell to a manager, but studies shows that the time is actually well-
done, partly in order to make progress in the project and partly to ensure that
team participants stay up to date with the technology development. The idea
supports SCRUM, where it is absolutely crucial that you are constantly
product-oriented rather than activity-oriented.
Another question is what you do at the end of a sprint if you find that some
of the work is not done. Here the rules are quite accurate:
1. Product Backlog, that is an ordered list of all stories that might be needed
in the final product
2.Sprint Backlog, that are selected stories from Product Backlog to be
delivered through a sprint, along with the Sprint Goal and sprint plans for all
stories in the Sprint Backlog
3. Increment, that is the set of all the Product Backlog stories completed so
far in the project
4. The definition of Done, that is the understanding of what it means that a
piece of work to be considered completed
5. Monitoring Progress towards a goal, that are the performance
measurement and forecast for the whole project
6. Monitoring Sprint Progress, that is the performance measurement and
forecasts for a single sprint
You should be aware that the literature regarding SCRUM defines the exact
content of these artifacts and also typical tools that you can use.
1. cost
2. time
3. quality
4. features
Scholarships
Master programmes in
Business & Economics | Behavioural Sciences | Computer Science/IT | Cultural Studies & Social
Sciences | Design | Mathematics | Natural Sciences | Technology & Engineering
where the latter might be the most important as a measure of what the
program should be capable of, but the four variables are of course not
independent and in order to meet the cost and time requirements, it can
easily mean that it is necessary to quench either quality (what is always
short-term) or features. The only thing new in these variables is that the
method from the outset focuses on the four key areas and controls them.
1. Planning
2. Small releases at short intervals
3. System metaphors
4. Simple design
5. Test
6. Frequent refactorization
7. Pair-programming
8. Common ownership of the program code
9. Continuous integration
10.Affordable work rate
11.An overall development team
12.Common code standard
and to be successful with the method, it is considered crucial that these
principles are respected.
There is much more about XP, and much are written about XP and gained
experience, and it all shows – at least if you ask the method’s advocates –
that the method is particularly useful when the goal is to develop quality
software.
3 TEST-DRIVEN DEVELOPMENT
TDD is based on the use of unit test and in this book JUnit (see possibly the
Java 3 book), but as a very simple example to illustrates some of the idea
with TDD I will show the development of a program where you can convert
between three temperature units:
1. celsius
2. fahrenheit
3. kelvin
The following shows the procedure.
I start with a JavaFX project, which I have called Degrees. In this case, the
program must consist of a user interface class – called Degrees, created by
NetBeans – and a class Converter that will implement the necessary
conversion methods. I want to think of the class Converter as the program’s
model and to write this class i will start with a test class. As a first step,
under Projects, right-click on the project name and select New | JUnit Test
(see below). Here I have:
The latter is not necessary, but in this case, I do not apply these initialization
methods, but often you can let NetBeans create them as they as default are
empty and therefore do not perform anything. When you click Finish,
NetBeans creates the following test class:
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT
test-drIven development
TEST-DRIVEN DEVELOPMENT
package models;
import org.junit.Test;
import static org.junit.Assert.*;
The task now is to add test methods to the test class. I start with the
following method:
@Test
public void fahrenheitToCelsius() {
}
PROCESS: SOFTWARE DEVELOPMENT PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT
test-drIven development TEST-DRIVEN DEVELOPMENT
TEST-DRIVEN DEVELOPMENT
which is nothing but a simple test method. Here I have added a single
statement:
which is nothing but a simple test method. Here I have added a single
statement:
@Test
public void fahrenheitToCelsius() {
@Test
@Test
public void fahrenheitToCelsius()
Again you get a translation error, but you can use ALT + Enter in the same
way as above, Again you get a translation error, but you can use ALT +
Enter in the same way as above,
Again you get a translation error, but you can use ALT + Enter in the same
way as above, and by clicking the mouse you can use NetBeans to create
the method ftoc()::
and by clicking the mouse you can use NetBeans to create the method ftoc() :
package models;
package models;
class Converter
class Converter
{
{double ftoc(double d)
double ftoc(double d)
{
{throw new UnsupportedOperationException("Not supported yet.");
If you repeat the test, it will fail, as the method can now raise an exception.
The test method If you repeat the test, it will fail, as the method can now
raise an exception. The test method If you repeat the test, it will fail, as the
method can now raise an exception. The test method
If you repeat the test, it will fail, as the method can now raise an exception.
The test method
must therefore be updated:
must therefore be updated:
@Test
@Test
public void fahrenheitToCelsius()
public void fahrenheitToCelsius()
{
for (int i = 0; i < FC.length; ++i)
for (int i = 0; i < FC.length; ++i)
The only difference is that the test method now tests a method ctof() and that it is the Celsiusctof()
must be created, which must be created, whichvalue in the table, which is used as a
parameter. The method ctof() must be created, which value in the table,
which is used as a parameter. The method ctof() must be created, which
I like NetBeans do in the same way as above. Next, the method must be
implemented,I like NetBeans do in the same way as above. Next, the method must be
implemented,I like NetBeans do in the same way as above. Next, the method must be implemented,
I like NetBeans do in the same way as above. Next, the method must be
implemented,
which consists simply of isolating the variable ff in the above formula:
which consists simply of isolating the variable f in the above formula:
double ctof(double d)
double ctof(double d)
double ctof(double d)
double ctof(double d)
{return d * 9 / 5 + 32;
{return d * 9 / 5 + 32;
}return d * 9 / 5 + 32;
} return d * 9 / 5 + 32;}
}
Then the unit test is performed again and it should be without error. Again, a
refactoring Then the unit test is performed again and it should be
without error. Again, a refactoring Then the unit test is performed again
and it should be without error. Again, a refactoring
The formula for converting Kelvin to Celsius is: The formula for
converting Kelvin to Celsius is: The formula for converting Kelvin to
Celsius is:
c = k – 273.15
c = k – 273.15
c = k – 273.15
c = k – 273.15
where k indicates degrees measured in Kelvin. Similarly, the formula for
converting Kelvin
where k indicates degrees measured in Kelvin. Similarly, the formula for
converting Kelvin
where k indicates degrees measured in Kelvin. Similarly, the formula for
converting Kelvinwhere to Fahrenheit is: indicates degrees measured in Kelvin. Similarly,
the formula for converting Kelvin
to Fahrenheit is:
to Fahrenheit is:
f = k * 9 / 5 – 459.67
f = k * 9 / 5 – 459.67
f = k * 9 / 5 – 459.67
f = k * 9 / 5 – 459.67
38
38
PROCESS: SOFTWARE DEVELOPMENT
test-drIven development
TEST-DRIVEN DEVELOPMENT
First, the test class is expanded with two new static tables:
private static double[][] KC = { { 0, -273.15 },
{ 10, -263.15 },
...
{ 1000, 726.85 }
};
};
where the first is a conversion table from Kelvin to Celsius, while the other
is a conversion
where the first is a conversion table from Kelvin to Celsius, while the other
is a conversion
table from Kelvin to Fahrenheit. Next, the test methods are written for each
of the four
table from Kelvin to Fahrenheit. Next, the test methods are written for each
of the four
new methods and the new methods are implemented. I do not want to show
the code for
new methods and the new methods are implemented. I do not want to show
the code for
the four new test methods or the implementation of the four methods, as they
are all in
the four new test methods or the implementation of the four methods, as they
are all in
principle identical to the above – just other test data and other formulas are
used. When all
principle identical to the above – just other test data and other formulas are
used. When all
unit tests are performed without errors, you can assumes that the class
Converter is complete
unit tests are performed without errors, you can assumes that the class
Converter is complete
and ready to be used. It happens in the class Degrees, which opens a simple
window, nor
and ready to be used. It happens in the class Degrees, which opens a simple
window, nor
here I will show the code.
here I will show the code.
The class Converter is quite simple, and it’s hardly clear what you’ve
achieved by starting
The class Converter is quite simple, and it’s hardly clear what you’ve
achieved by starting
typing the test methods, but basically you get two things:
typing the test methods, but basically you get two things:
1. When writing a class, you decide through the test methods how the class’
methods
1. When writing a class, you decide through the test methods how the class’
methods should work and when the methods are implemented, you can test
them immediately
should work and when the methods are implemented, you can test them
immediately
using the test methods.
using the test methods.
2. If you later update or change a method, you have the necessary test
method, so
2. If you later update or change a method, you have the necessary test
method, so
you can immediately test where the method has errors.
you can immediately test where the method has errors.
Test Driven development is one of the many initiatives in system
development that are
Test Driven development is one of the many initiatives in system
development that are worth learning and being good at, as the method gives
very good results both in small and
worth learning and being good at, as the method gives very good results both
in small and
large projects.
large projects.
3939
4 DESIGN PATTERNS
At one point, system development began to talk about design patterns, and
like everything else new, design patterns received great attention – and
perhaps even some interpreted as the solution to this world’s problems in
software development. It is probably a little over-interpreted, but conversely,
knowledge of design patterns is important for software development in
practice. It all started with a book
- Singleton
- Factory
- Adapter
- Observer
and there are many others, and since Gang of Four defined 23, many others
have been defined. The latter can be a challenge as many patterns look
similar and can be difficult to distinguish, and there has also been a tendency
to define patterns for anything, but it does not change that patterns are
important and that it pays to teach them.
The patterns of Gang of Four and many others concerns concrete issues in
programming, but other patterns are more general and are often composed of
several patterns. One example is MVC, which is a pattern for the design of a
GUI program. It is also a design pattern that expresses others’ experience of
how to design a GUI program. If you do, others who must maintain the
program knows how the program is designed. The pattern is described in
these books. It’s a complex pattern, and it is a pattern that is found in several
variants. It expresses the fact that it is actually difficult to define design
patterns if they are to be general and therefore MVC exists in so many
variants, which are determined by both software platforms and development
tools.
Another important reason for using design patterns is that developers in this
way have a family of common concepts. For example, if I say that a class in
a program is an adapter, I’ve told others that it’s a class that is used to
smooth the differences to other classes, and I can even look up a book about
design patterns and see what an adapter is and how it is used.
and if you read the literature you will be presented with a number of other
quality factors, but in addition to that, you can add that the project is
completed within the estimated resource consumption and that it is
completed on time.
5.1 REFACTORING
In order to meet these requirements, you have to work systematically and
follow a method, and the four basic activities in system development are, as
already mentioned many times:
1. analyse
2. design
3. programming
4. test
Once you have written the code and tested it and found that it meet the
requirements, the code has been through a process where you have
developed on the code, tested it, corrected, adjusted, expanded and so on and
the result will very often be a code that is characterized by:
- Variables not used and which must therefore be removed.
- Methods not used, which should therefore be removed.
- Two or more methods that almost do the same, and where you can reduce
to a
and here it is absolutely the last, which is the biggest problem. Therefore, the
code must be refactored, which can be considered as a cleanup process to
clean the code for the above inconvenience.
There may be several reasons for using log files, and one is to collect
statistic data relating to the application’s use, perhaps in order to improve the
program later. Another and perhaps even more important application is
logging of an error message. Once a program has been put into operation and
errors occurs, they are reported to developers who then have the correct
error. In order for this to be possible, you need some information, and here I
would like to say that an error handling, where the program just crass and
the screen is filled with errors regarding exceptions, simply can not be used.
Firstly, users will not accept such malware, and it creates frustration and
unwillingness towards the development organization, and secondly, it is far
from the assumption that users are reported to such errors, and at best, you
will be notified that the program is not working. As a developer, you know
critical places where a program can go down and here you can encapsulate
the code that can fail in a try/catch block and in case of an exception write a
message in a log file. As a developer, in case of an error, you can ask to get
the log file, and here you can see when and where in the program there have
been errors.
Such error logging can be a very big help in troubleshooting, just be careful
about where in the code you write in the log file. In principle, the error log
must be empty and therefore it may be a nice check of the program to
periodically inspect the log file.
Bioinformatics is the exciting field where biology, computer science, and mathematics meet.
We solve problems from biology and medicine using methods and tools from computer science and
mathematics.
Read more about this and our other international masters degree programmes at www.uu.se/master
6 POKER
I want to close this book and thus also this series of books about software
development in Java with another example of a program. The goal is similar
to the final examples in the other books to show the development process,
but the task/project does not directly follow any of the previous system
development methods, but uses elements from several of them and what is
otherwise mentioned in these books. The reason is partly the size of the
program, where it is still a small program in size, and partly that the program
is written by a single person. For these reasons, it does not make sense to
use, for example, SCRUM or Unified Process, but conversely, elements of
the methods will be used. In fact, it also reflects how system development
methods are used in practice, where elements of concrete methods are used,
and because the following is a slightly bigger program than what I have
otherwise presented in these books, but in relation to the development of
many IT systems in practice, it is still a very small program.
6.1 VISION
The task is to write a program where a player (user) can play poker on a
single computer, a little like what for many is a very well-known Windows
program called Hearts Free, but the card game here is instead poker. The
user is playing against a number of virtual players. It is thus a usual GUI
program.
1. Texas Hold’em
2. Omaha
3. 7 Card Stud
4. 5 Card Draw
and it is the player (user) who decides what kind of game to start.
The program’s vision is entertainment and you should not play with real
money, but only about chips (jetons). The player must have an account that
over time keeping track of how much the player (the user) has won and lost,
and it must be possible to insert and raise the account.
Poker is played with all 52 cards and without jokers. Basically, the cards
rank in ascending order are:
- two, three, four, five, six, seven, eight, nine, ten, jack, queen, king and ace
In some cases, the color also has significance, and the rank is then (in
ascending order):
- diamonds, hearts, spades and clubs
A player must in one round form a hand consisting of 5 cards and the result
of the hand is one of 9 options, arranged according to falling value:
Straight flush Five consecutive cards of the same color, making it the hand
with the highest value. An example could be
- 5 spades: 8, 9, 10, Jack and Queen
If there are two or more players who have straight flush, the highest card
determines the rank, and if the cards are the same, the color determines the
rank.
Four of a kind Four cards of same value, and an example could be
- diamonds 4, hearts 4, spades 4, clubs 4 and another card
The last card has no significance for the rank and has two or more players
four of a kind, the highest card of the four of a kind determines the rank.
Full house Three of a kind and one pair, for example
- diamonds 8, spades 8, clubs 8, hearts king, spades king
If two or more players have a full house the highest of the three of a kind
determines the rank.
Copenhagen Master of Excellence
Copenhagen Master of Excellence are two-year master degrees taught in
English at one of Europe’s leading universities
cultural studies
religious studies
Come to Copenhagen and aspire!
Apply now at
science
www.come.ku.dk
Flush
Five cards in the same color, but not necessarily continuous values, for
example
- diamonds 2, diamonds 7, diamonds 8, diamonds 10 and diamonds queen
If two or more players have a flush determines the highest value of the first
card the rank, which they are different, and if all cards the same value
determines the color the rank.
Straight
Five cohesive cards, but not necessarily in the same color, for example
- diamonds 5, clubs 6, spades 7, heartsr 8 and spades 9
Having multiple players straight determines the highest card the rank and
has all cards the same value determines the color of the highest card the
rank.
Three of a kind
Three cards of same value, where the last two cards have a different value
and are not a pair, for example
- hearts jack, spades jack, clubs jack, diamonds 2 and hearts 5
In the case where two or more players have three of a kind, the rank of the
highest card (for the 3 of a kind) determines the rank. The last two cards
therefore never have a meaning for the rank.
Two pairs
Two pairs: Two different pairs, where the last card must have another value,
for example
- spades 2, clubs 2, hearts king, spades king and clubs ace
If two or more players have two pairs, it is the largest pair that determines
the rank. If the largest pair has the same value, the rank is determined as the
largest of the smallest pair, and if this pair has the same value, the rank is
determined of the last card. If also the last cards have the same value, the
rank is determined as the color of the last card.
One pair Two cards with the same value, where the last three cards all have
a different value and do not have the same value as the two cards that make
up the pair, for example
- spade ace, clubs ace, hearts 4, hearts 7 and diamonds jack
Have two or more players a pair the biggest pair determines the rank. Do
they have two pairs of the same value, the rank is determined as the highest
card of the first of the three remaining cards that are different and have all
three remaining cards the same value determines the color of the highest of
these cards determines the rank.
A single game is called a round, and for each round the players are switched
as dealer. The game is played by players continuously building their hand as
the cards are dealt. How it happens and how the hand is formed depends on
the current variant (Texas Hold’em, Omaha and so on). For each variant
there are a number of betting rounds where players either deposit money into
a pool (a pot) or leave the round (and the money they have already deposited
are thus lost). You can win a round in poker in two ways:
1. By having the best hand at showdown (when all betting rounds are
completed and the round is over).
2. By being the last remaining player in the current round.
For a round, as mentioned above, there are more betting rounds where each
remaining player bets, thus either depositing an amount in the pot or leaving
the current round (dropping out). You have the following options (slightly
dependent of the current variant):
1. FOLD, the player gives up and is no longer a player in the current round.
2. CHECK, the player wishes to continue the round, but without making a
deposit (only possible if in the current betting round there is not already a
player who has deposit money in the pot).
3. BET, the player deposits an amount in the pot (only possible if there is not
already a player who has deposited an amount) or there is another player
who has CHECK.
4. CALL, you deposit the same amount as the last BET or RAISE and is thus
the least amount that allows you to continue playing.
5. RAISE if there is already a BET, a player can increase the deposit amount
and all remaining players who are still there must choose either CALL,
RAISE or FOLD.
In connection with BET and RAISE, there will usually be an upper limit for
the amount of money you have to deposit.
Brain power
By 2020, wind could provide one-tenth of our planet’s electricity needs. Already today, SKF’s
innovative knowhow is crucial to running a large proportion of the world’s wind turbines.
Up to 25 % of the generating costs relate to maintenance. These can be reduced dramatically thanks to
our systems for on-line condition monitoring and automatic lubrication. We help make it more
economical to create cleaner, cheaper energy out of thin air.
By sharing our experience, expertise, and creativity, industries can boost performance beyond
expectations.
Therefore we need the best employees who can meet this challenge!
With regard to the different variants, the current program should support 5
variants:
- Texas Hold’em
- Omaha
- 7 Card Stud
- 5 Card Draw
- 5 Card Stud
Here is there probably not no game as the last version, and at least it’s not a
game found on the usual poker game pages, but it’s a very simple poker
game and that’s how I’ve learned to play poker. The game is similar to 7
Card Stud, and hence the above name.
Chips
In this program, the smallest amount is a chip (or jeton), which in principle
is just a unit. When a new game is started, each player gets a number of
chips, and one player is released from the game when the player does not
have more chips. If the player is the user, the game is over.
In this game each player have two closed cards (which only the player can
see). In addition, 5 open cards are placed on the table (cards that everyone
can see). Each player must then form the best possible hand with 5 cards
based on his own two closed cards and the 5 open cards on the table. It is
optional if one or both of the closed cards are included in the hand.
The game has 4 betting rounds, and the game progresses (in this program) as
follows:
1. At the start of a game, the user is selected as a dealer. The dealer changes
a clockwise position after each round.
2. Before the players get cards, all players must put a blind in the pot. Then
all players at the table are given two closed cards.
3. Then the first betting round begins at the player after the dealer.
4. Now three cards all with the face upside are placed at the table – the so-
called ‘flop’. It is common cards and can be used by all players to create
their best poker hand. Then there is another betting round, where it is the
first player after the dealer, who is still in the game, that begins.
5. Another open common card is placed on the table. This is called the ‘turn’
card. Then a third betting round follows with the same pattern as above.
6. The fifth and last common card – the ‘river’ card – is placed on the table,
after which the game’s last betting round is performed, exactly as the
previous two betting rounds.
7. If there are two or more players who have not yet thrown their cards after
the last betting round, the winner will be settled at a showdown. Each player
builds the best five-card poker hand out of his own two personal cards and
the five common cards on the table (the player does not have to use his own
closed cards). The player with the best poker hand wins the pot. If there is
only one player left, this player has won the pot.
Omaha
7 Card Stud
In this variant there are 5 betting rounds. The variation differs from Texas
Hold’em and Omaha in that each player is assigned his own open personal
cards – that is cards, which may only be used by one player. There is thus no
common cards. In 7 Card Stud, each player receives from the start two
closed cards and one open card, followed by three more open cards one at a
time with a betting round between each and finally another closed card.
Thus, each player ends finally at the end of the round with seven cards –
three closed and four open. The game progresses as follows:
5. Another card is given with face up and another betting round (the 4th
betting round) takes place according to the above pattern.
6. A seventh and last card is given to the remaining players in the round, but
with the face down (a closed card) and the last betting round (the 5th betting
round) takes place according to the same pattern as the previous one.
7. If there are two or more players who have not yet folded their cards after
the last betting round, the winner will be settled at a showdown where each
player will make the best five-card poker hand out of his own seven cards.
The player with the best hand wins the pot. If there is only one player left,
this player has won.
5 Card Draw
It is the original poker game and is simpler than the above variants, and there
are only 2 betting rounds. The procedure is as follows:
If there are 6 players, it means that you in principle needs 60 cards, which is
not possible. It is decided to ignore this problem as it is perceived as
theoretically that all players throw all there cards. Should it happen, it is
assumed that the game is ignored, but the pot will remain to the next round.
5 Card Stud
As mentioned, it is a simplified game with four betting rounds and the
procedure is as follows:
If there are two or more players who have not yet thrown their cards after the
last betting round, the winner will be settled at a showdown, otherwise the
remaining player will win the pot.
1. iteration
Development of prototype for 5 Card Stud. The purpose is primarily to get
started, including the preparation of a preliminary design of the user
interface. You should not be able to complete a hole round, but you should
be able to deal the first two cards so that all the technical regarding showing
the cards is in place.
2. iteration
An algorithm must be developed for how a virtual player should play 5 Card
Stud. The algorithm should include
- how the virtual player should act in a betting round, for example, how
much the player has to bet (BET of BIG BET), when the player has to raise
(RAISE or BIG RAISE) and when the player should choose FOLD and
possibly bluff
- who should start a betting round
- who wins at showdown
In addition, the iteration must include an algorithm for how the individual
betting rounds should proceed depending on whether it is the user or a
virtual player who starts the betting round.
3. iteration
The overall design of the program’s classes, which includes important
decisions for which classes the program should primarily consist of.
Implementation of the poker variant 5 Card Stud. The iteration thus includes
implementation of all algorithms from iteration 2. After this iteration, you
should be able to play poker with the program, but only the simple 5 Card
Stud variant and there should be no user administration.
4. iteration
The Iteration includes decisions and designs regarding how to save the
program’s data and what data to save. It is decided that data should be stored
in common files, partly because it should be simple to install the program,
and partly because data is not critical, which means that the program’s vision
is merely entertainment. It also includes the design and implementation of
the classes that are necessary for users’ accounts.
Finally, the iteration must include an extension of the version from iteration
3 extended with login, including the maintenance of users and their
accounts. The iteration must also implement the user dialog to start a new
game.
This e-book is made with SETASIGN
SetaPDF
PDF components for PHP developers
www.setasign.com
5. iteration
Implementation of the variant 7 Card Stud. It includes new algorithms
corresponding to the algorithms developed for 5 Card Stud, but it is expected
that these algorithms will substantially resemble the algorithms from
iteration 2, and part of the algorithms may be used directly. In addition, the
iteration will include a change of the user interface corresponding to the fact
that each player now has more cards.
6. iteration
Implementation of Texas Hold’em. In the same way as in iteration 5, this
iteration includes implementation of new game algorithms, as well as
developing a new user interface.
7. iteration
Implementation of Omaha. It is perceived as a simple iteration, which is
primarily a matter of modifying the result of iteration 6.
8. iteration
Implementation of 5 Card Draw. It is the last variation of the game, and
after this iteration, the program is in principle complete. The iteration
includes new algorithms corresponding to 5 Card Draw, including where the
virtual players must make decisions as to which cards they wish to
exchange. In addition, the variant requires the user interface to change.
9. iteration
This iteration includes improving the user interface, including colors and
fonts. Optionally, a form of settings must also be implemented.
6.4 ITERATION 1
The window below shows the prototype where a 5 Card Stud game has been
started with 5 players and the 5 players are given the first 2 cards:
The bottom player is the user. Below each player there is a TextField
showing the player’s amount of money (the number of chips) and the field in
the center is the pot. At the bottom, the buttons are the commands that the
user must use to play. The meaning is as follows:
- When you start a new game, only NEW is enabled and when the user clicks
on it, a new round starts.
- After that, only DEAL is enabled and when clicked, cards is dealt out
starting with the player who is after the dealer. In the prototype the user is
the dealer. After dealing cards, only the BID button is enabled.
- When you click on BID, a bidding round starts and when it’s the turn of the
user to bet, the remaining 7 buttons are enabled as they make sense, and it is
- CHECHK, BET, BET+, FOLD
- CALL, RAISE, RAISE+, FOLD
- After the player has clicked on one of the buttons they are all disabled and
the remaining (virtual) players are betting. Then there are three options: 1.
The betting round has not been completed because a player has raised the
deposit. If it is the case, BID will be enabled and the betting round will
continue as described above, however, the player may only choose
- CALL, RAISE, RAISE+, FOLD
FOSS works diligently with innovation and development as basis for its growth. It is reflected in the
fact that more than 200 of the 1200 employees in FOSS work with Research & Development in
Scandinavia and USA. Engineers at FOSS work in production, development and marketing, within a
wide range of different fields, i.e. Chemistry, Electronics, Mechanics, Software, Optics, Microbiology,
Chemometrics.
We offer
A challenging job in an international and innovative company that is leading in its field. You will get the opportunity to work with the most advanced technology together with highly
skilled colleagues.
Read more about FOSS at www.foss.dk - or go directly to our student site www.foss.dk/sharpminds where you can learn more about your possibilities of working together with us on
projects, your thesis e
tc.
Dedicated Analytical Solutions
FOSS
Slangerupgade 69
3400 Hillerød
Tel. +45 70103370
www.foss.dk
The Family owned FOSS group is
the world leader as supplier of
dedicated, high-tech analytical
solutions which measure and
control the quality and produc
tion of agricultural, food, phar
maceutical and chemical produ
cts. Main activities are initiated
from Denmark, Sweden and USA
with headquarters domiciled in
Hillerød, DK. The products are
marketed globally by 23 sales
companies and an extensive net
of distributors. In line with
the corevalue to be ‘First’, the
company intends to expand
its market position.
resources.css contains a style sheet that for now only contains one
style used in this program –resources.css
contains a style sheet that for now only
contains one style used in this program – in the class poker.tools contains a
few help classes. One class is called Images and
in the class CardView
CardView . . poker.tools contains a few help classes. One class is called Images
and
is a singleton that makes the images of the cards available. The other class is
CardView that
is a singleton that makes the images of the cards available. The other class is
CardView that
is a GridPane with an ImageView and thus a simple component that shows a
playing card
is a GridPane with an ImageView and thus a simple component that shows a
playing card with a frame around.
with a frame around.
With respect to the package poker.models, 4 enumerations are defined:
With respect to the package poker.models, 4 enumerations are defined:
1. CardColor, representing the four card colors
1. CardColor, representing the four card colors
2. CardValue, representing the 13 card values
2. CardValue, representing the 13 card values
3. PokerGames, which lists the 5 poker variants
3. PokerGames, which lists the 5 poker variants
4. PokerBets, which indicates the player’s bets
4. PokerBets, which indicates the player’s bets
and 5 classes. Card represents a playing card:
and 5 classes. Card represents a playing card:
public class Card implements Comparable<Card> {
private CardColor color; private CardValue value;
62
poker
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
These are classes that I have shown before and they work basically the
same way as in the program Poker from the book Java 4. The following
class, which is the beginning of a model for the game itself, is also
defined, but it is not yet used to much:
public class Game {
private ObjectProperty<Integer> size = new SimpleObjectProperty(5);
private ObjectProperty<Integer> blind = new SimpleObjectProperty(1);
private IntegerProperty start = new SimpleIntegerProperty(100);
private ObjectProperty<PokerGames> poker =
new SimpleObjectProperty(PokerGames.CARD5);
private Cards cards = new Cards();
Finally, there is a class representing the cards that a given player has:
public class Hand {
private List<Card> cards = new ArrayList();
and in addition there is an exception class.
and in addition there is an exception class.
Then there is the poker.views package that contains view and presenter
classes. Preliminary
Then there is the poker.views package that contains view and presenter
classes. Preliminary
there is 4:
there is 4:
1. MainView and MainPresenter , which defines the main window with
the buttons
1. MainView and MainPresenter, which defines the main window with the
buttons
and maybe later a toolbar or menu.
and maybe later a toolbar or menu.
2. HandView and HandPresenter , which shows the individual player’s
cards and the
2. HandView and HandPresenter, which shows the individual player’s cards
and the
number of player’s chips.
number of player’s chips.
3. Card5View and Card5Presenter , which defines a pane for the current
poker variant.
3. Card5View and Card5Presenter, which defines a pane for the current
poker variant.
4. TableView and TablePresenter , there are basic classes for the above.4. TableView and
TablePresenter, there are basic classes for the above.
The iteration ends with a simple refactoring, which is nothing but a
simple cleanup in
The iteration ends with a simple refactoring, which is nothing but a simple
cleanup in
the code.
the code.
PROCESS: SOFTWARE DEVELOPMENT poker
PROCESS: SOFTWARE DEVELOPMENT POkER
6.5
6.5
ITERATION 2
ITERATION 2
The following algorithms have a parameter of the type
Card[] that represents a player’s
Card[] that represents a player’s
cards. It is assumed that the cards are sorted in descending order.
cards. It is assumed that the cards are sorted in descending order.
The first algorithms are used to determine the value of a player’s cards. The
algorithms are
The first algorithms are used to determine the value of a player’s cards. The
algorithms are
help algorithms used by the other algorithms.
help algorithms used by the other algorithms.
// Tests if there among the cards are n cards with the same value.
// The algorithm assumes that the cards not contains more than n
cards with the
// same value, and if n = 2 that the hand does not contain two
pairs. Card[] sameValue(Card[] c, int n)
{
put the first card in a list
{
put the card in the list
if the list contains n cards return the list
}
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
else {
clear the list
put the card in the list
}
}
return the empty list }
return false
}
else
{
return false
}}
}}
There will probably be a need for multiple algorithms of similar kind, and as
tests of where
There will probably be a need for multiple algorithms of similar kind,
and as tests of where a sequence of cards may have a certain value, and
they will, if appropriate, look like the
a sequence of cards may have a certain value, and they will, if
appropriate, look like the above and will generally be simple.
above and will generally be simple.
In 5 Card Stud, the player with the best open cards must always start the
betting round.
In 5 Card Stud, the player with the best open cards must always start the
betting round. There are 4 betting rounds and an algorithm is defined for
each betting round, which
There are 4 betting rounds and an algorithm is defined for each betting
round, which
returns the index for the player to start the betting round. As a parameter, the
algorithms
returns the index for the player to start the betting round. As a
parameter, the algorithms
have an array of the cards to be tested, and it is assumed that index 0 always
indicates the
have an array of the cards to be tested, and it is assumed that index 0
always indicates the
user’s hand.
user’s hand.
// Returns the index of the player to start the first betting round.
int round1(Card[] c)
{{
if there is a player with a pair return the index for the player
with the highest pair
else return the index of the player with highest card
}}
// Returns the index of the player to start the third betting round.
// Each player has three open cards and the highest value can then
be a three
// of a kind, and is it not the case a player can have one pair.
int round3(Card[][] c)
{
if there is a player with 3 of a kind return the index for the
player with the highest cards for 3 of a kind
else if there is a player with a pair return the index for the
player with the highest pair
else return the index of the player with highest card
// Returns the index of the player to start the last betting round.
// Each player has four open cards and the highest value can then be
four
// of a kind, and if not three of a kind, and is it not the case a
player
// can have two pairs and if not so one pair.
int round4(Card[][] c)
{
The Wake
the only emission we want to leave behind
.QYURGGF'PIKPGU/GFKWOURGGF'PIKPGU6WTDQEJCTIGTU2TQRGNNGTU2TQRWNUKQP2CEMCIGU2TKOG5GTX
6JGFGUKIPQHGEQHTKGPFN[OCTKPGRQYGTCPFRTQRWNUKQPUQNWVKQPUKUETWEKCNHQT/#0&KGUGN6WTDQ
2QYGTEQORGVGPEKGUCTGQHHGTGFYKVJVJGYQTNFoUNCTIGUVGPIKPGRTQITCOOGsJCXKPIQWVRWVUURCPPKPI
HTQOVQM9RGTGPIKPG)GVWRHTQPV
(KPFQWVOQTGCVYYYOCPFKGUGNVWTDQEQO
else if there is a player with a pair return the index for the
player with the highest pair
else return the index of the player with highest card
}
}
else if there is a player with 4 of a kind return the index for the
player with the highest cards for 4 of a kind
else if there is a player with full house return the index for the
player with the highest full house
else if there is a player with flush return the index of the player
with the highest flush
else if there is a player that has a straight return the index of
the player
with the highest straight
else if there is a player with 3 of a kind return the index for the
player with
the highest cards for 3 of a kind
else if there is a player with two pairs return the index for the
player with
the highest two pairs
else if there is a player with a pair return the index for the
player with
the highest pair
else return the index of the player with highest card
}
The last algorithms relates to how the virtual player should act in a
betting round, for example, to say how much the player has to bet
(BET), and how much when the player raises (RAISE) and where the
player should choose CHECK, FOLD and possibly bluff. The
player in question will make his choice based on his own cards and the
other players’ open
player in question will make his choice based on his own cards and the other
players’ open
cards. How the player makes his choice is determined from the current
betting round and
cards. How the player makes his choice is determined from the current
betting round and
hence how many cards the player can see and to make it harder to
predict the betting, the
hence how many cards the player can see and to make it harder to predict the
betting, the
choice is to some extent random. For each betting round there are two
situations:
choice is to some extent random. For each betting round there are two
situations:
1. that it is the player who is the first or round’s last bet was CHECK,
and the player
1. that it is the player who is the first or round’s last bet was CHECK, and
the player then has four options: BE = BET, B+ = BET double, CH =
CHECK, FO = FOLD
then has four options: BE = BET, B+ = BET double, CH = CHECK, FO =
FOLD 2. that a player has already bet, and thus has deposited money in
the pot, and in
2. that a player has already bet, and thus has deposited money in the pot, and
in this case there are four options: RA = RAISE, R+ = RAISE double,
CA = CALL,
this case there are four options: RA = RAISE, R+ = RAISE double, CA =
CALL, FO = FOLD
FO = FOLD
6868
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
For each bet, there are two options, such as CH or BE, but such that the first
one is chosen
For each bet, there are two options, such as CH or BE, but such that the first
one is chosen
with some probability or random. If a situation in the following algorithms
determines that
10, CH, BE
10, CH, BE
this means that the player randomly chooses CH in 10% of the cases, while
in other cases,
this means that the player randomly chooses CH in 10% of the cases, while
in other cases,
the player chooses BE. This means that it can be difficult to predict what the
player bets. The
the player chooses BE. This means that it can be difficult to predict what the
player bets. The
following 4 algorithms are all formulated using a five-column table, where
the first column
following 4 algorithms are all formulated using a five-column table, where
the first column
indicates a condition and the other columns indicates the player’s bet for the
two situations.
indicates a condition and the other columns indicates the player’s bet for the
two situations.
The individual rows should be perceived as if/else so that if a condition is
not met then the
The individual rows should be perceived as if/else so that if a condition is
not met then the
next one is tested. Note that the virtual player’s action can be fine-tuned by
introducing
next one is tested. Note that the virtual player’s action can be fine-tuned by
introducing
more rows in the tables, which will probably also be the case in the
implementation, and
more rows in the tables, which will probably also be the case in the
implementation, and
you should only perceive the following as examples of which conditions the
algorithm
you should only perceive the following as examples of which conditions the
algorithm
may contain.
may contain.
// Returns player's bet in the first betting round. // The value of
player's cards kan be one pair or high card. // The value of others
cards kan be high value.
PokerBets round1(Card[] player, Card[][] others)
{
}
// Returns player's bet in the secound betting round. // The value
of player's cards kan be
// 3 of a kind
// one pair
// same color
// can straight
// high card
// The value of others cards kan be one pair or high value.
PokerBets round2(Card[] player, Card[][] others)
{
Technical training on
ELECTRONICS
Motors, Shell, Siemens, BHP and Honeywell to name a few.
Our onsite training is cost effective, convenient and completely AUTOMATION & customisable to
the technical and engineering areas you want PROCESS CONTROL covered. Our workshops are all
comprehensive hands-on learning
experiences with ample time given to practical sessions and
}
// Returns player's bet in the last betting round. // The value of
player's cards kan be
// straight flush
// 4 of a kind
// full house
// flush
// straight
// 3 of a kind
// two pairs
// one pair
// high card
�e Graduate Programme
for Engineers and Geoscientists
www.discovermitas.com�e Graduate Programme
I joined MITAS
because
I wanted real responsibili�
www.job.oticon.dk
JAVA 20: ABOUT THE SYSTEM DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
PROCESS: SOFTWARE DEVELOPMENT POkER
others have two pairs 100 FO, B 100 FO, CA
others have two pairs 100 FO, B 100 FO, CA
others have one pair, that is bigger than
others have one pair, that is bigger than 100 FO, B 100 FO, CA the
100 FO, B 100 FO, CAthe players
players
others have one pair 20 B+, B 10 R, CA
others have one pair 20 B+, B 10 R, CA
others have the pair card more than 1 times 20 CH, B 10 FO, CA
others have the pair card more than 1 times 20 CH, B 10 FO, CA
others have the pair card 1 time 10 CH, B 10 R, CA
others have the pair card 1 time 10 CH, B 10 R, CA
else 20 B+, B 20 R, CA
else 20 B+, B 20 R, CA
Player has high value
Player has high value
others have high card, the values less than
others have high card, the values less than 10 CH, B 10 FO, CA
players cards 10 CH, B 10 FO, CA
players cards
others have a pair 50 FO, B 10 R, CA
others have a pair 50 FO, B 10 R, CA
others have bigger cards 30 FO, B 10 R, CA
others have bigger cards 30 FO, B 10 R, CA
else 100 CH, B 100 FO, CA
else 100 CH, B 100 FO, CA
}
}
In connection with the implementation and later when testing, there will
certainly be changes
In connection with the implementation and later when testing, there will
certainly be changes
to the above tables, partly as to which and how many conditions are
required, and partly
to the above tables, partly as to which and how many conditions are
required, and partly
as to the probabilities that will be used. If applicable, the above tables
will not be updated.
as to the probabilities that will be used. If applicable, the above tables will
not be updated.
The game’s value will largely be determined by how lucky it is with the
implementation of
The game’s value will largely be determined by how lucky it is with the
implementation of these algorithms and it is actually extremely difficult
(imposible) to implement the kind of
these algorithms and it is actually extremely difficult (imposible) to
implement the kind of algorithms so that an experienced poker player
can not win at all times.
algorithms so that an experienced poker player can not win at all times.
6.6 ITERATION 3
6.6 ITERATION 3
Compared to the prototype from iteration 1, there are no significant
changes to the overall
Compared to the prototype from iteration 1, there are no significant changes
to the overall
design, and the development follows the classic MVP design pattern for
JavaFX applications.
design, and the development follows the classic MVP design pattern for
JavaFX applications. With regard to the model layer, it is primarily
expanded with three new classes. A class
With regard to the model layer, it is primarily expanded with three new
classes. A class
Model has been addedModel has been added
public class Model {
public class Model {
protected IntegerProperty pot = new SimpleIntegerProperty(0);
protected IntegerProperty pot = new SimpleIntegerProperty(0);
The variable potpot represents the pot on the table and where players
deposit amounts (chips) in each betting round. It is defined as a JavaFX
property, so the user interface can bind to it. The next variable
game
game
Game
hands
The class’s methods are generally simple and consist primarily of getget
and setset methods. In addition, there are methods for maintaining the
variables
pot
pot
and
value
value::
public int bet() {
pot.set(value + getPot()); return value;
}
The methods are quite simple, but important as these are the methods
that the players call in connection with the individual betting rounds.
You should especially note the method
PROCESS: SOFTWARE DEVELOPMENT poker
call() , which has a parameter. If a player raises and another player has
already placed an amount in the pot, it is necessary to subtract this amount,
before the pot is updated and that is the goal of this parameter. The above
methods thus determines what it costs to play in the individual betting
rounds. Similar to the decisions in iteration 1, it is somewhat simplified in
relation to “real” poker games, and another purpose of the methods is also
that these rules need to be changed by overriding the methods in a derivative
class. It is also the reason why the two variables pot and value are defined
protected.
careers.slb.com/recentgraduates
PROCESS: SOFTWARE DEVELOPMENT poker
PROCESS: SOFTWARE DEVELOPMENT POkER
The first variable bigCard determines what the virtual players should
perceive as a big card
The first variable bigCard determines what the virtual players should
perceive as a big card
(JACK, QUEEN, KING and ACE), and the value is used in conjunction with
the betting
(JACK, QUEEN, KING and ACE), and the value is used in conjunction with
the betting
rounds. The value may need to be changed later into an option regarding the
program’s
rounds. The value may need to be changed later into an option regarding the
program’s
settings. The next variable cards is a list of a player’s cards and the variable
state is used to
settings. The next variable cards is a list of a player’s cards and the variable
state is used to
keep track of whether a card is open (facing up) or closed (facing down).
The variable foldedkeep track of whether a card is open (facing up) or closed (facing down).
The variable folded
indicates whether the player has folded and thus dropped out of the round.
The variable
indicates whether the player has folded and thus dropped out of the round.
The variable
place indicates the player’s position at the table, where position 0 is always
perceived as theplace indicates the player’s position at the table, where position 0 is always
perceived as the
physical player, while the variable raise indicates how many times a player
has bet RAISE
physical player, while the variable raise indicates how many times a player
has bet RAISE
or BIGRAISE in a betting round. The value is used to set a limit for how
many times a
or BIGRAISE in a betting round. The value is used to set a limit for how
many times a
player must RAISE in the same betting round. Finally, there is the variable
value, which
player must RAISE in the same betting round. Finally, there is the variable
value, which
indicates how many chips the player has already deposited in the pot in the
current betting
indicates how many chips the player has already deposited in the pot in the
current betting
round. The value is used in conjunction with CALL if another player bet
RAISE. Finally,
round. The value is used in conjunction with CALL if another player bet
RAISE. Finally,
there is the variable jetons , which indicates the player’s amount of chips, and
it is defined
there is the variable jetons, which indicates the player’s amount of chips, and
it is defined
as a JavaFX property, so that for each player it can bind to the user interface.
as a JavaFX property, so that for each player it can bind to the user interface.
Regarding a limit on how many times a player can bet RAISE in a betting
round, it is not
Regarding a limit on how many times a player can bet RAISE in a betting
round, it is not
in agreement with a real poker game, but it is included here as otherwise it is
difficult to
in agreement with a real poker game, but it is included here as otherwise it is
difficult to
get the virtual players to act properly. So far, this limit is 2 for the first three
betting rounds
get the virtual players to act properly. So far, this limit is 2 for the first three
betting rounds
and 3 for the last betting round, but the limit may need to be changed to an
option.
and 3 for the last betting round, but the limit may need to be changed to an
option.
The class has many methods and implements all the algorithms regarding the
value of a
The class has many methods and implements all the algorithms regarding the
value of a
hand, including the methods that the virtual players must use to determine
their bets during
hand, including the methods that the virtual players must use to determine
their bets during
a betting round. There are many methods, and many of them are defined as
both instance
a betting round. There are many methods, and many of them are defined as
both instance
methods and static methods.
methods and static methods.
JAVA 20: ABOUT THE SYSTEM DEVELOPMENTpoker PROCESS: SOFTWARE
DEVELOPMENTPOkER
PROCESS: SOFTWARE DEVELOPMENT POkER
The first constant is the limit of how many times a player must RAISE,
and the next variable is the program’s model. When the program has to
deal out cards, a smaller delay is inserted between each card (so the user
can follow the cards being dealt out). The same goes for the bets, where
there is a delay between each player’s bet – again in order for users to
keep track of how the virtual players act (simulates they think). It
requires that the algorithms for dealing of cards and the betting rounds
are performed in their own threads, which complicates the code a bit to
ensure proper user interface update, where the user interface needs to
be updated with Platform.runLater() . The last two variables in the class
AbstractPlayer are used in that context.
84
PROCESS: SOFTWARE DEVELOPMENT poker
where the first 4 are the methods for the 4 betting rounds. The first
parameters are the player’s card and the next parameter others is the other
players’ open cards. The third parameter indicates whether it is the first
betting round, while the last parameter indicates the current player. The last
5 methods are used to determine who will start a betting round, which is
determined by the players’ open cards.
In addition to the model classes, there are the classes in the user interface,
and here the changes primarily concerns the class Card5Presenter. It is also
expanded considerably and is until this time the program’s most complex
class equivalent to the fact that this class contains the entire game logic.
private LogFile() {
try
{
writer = new BufferedWriter(new FileWriter(path)); }
catch (Exception ex)
{
System.out.println("Open Error"); }
}
writer.close();
writer = new BufferedWriter(new FileWriter(path)); }
The class is quite simple to understand. You can then let the program write
to the log on
The class is quite simple to understand. You can then let the program write
to the log on
specific places, which can make it much easier to find out where the
program is failing.
specific places, which can make it much easier to find out where the
program is failing.
Of course, the log file should not be part of the completed program, and the
class – and all
Of course, the log file should not be part of the completed program, and the
class – and all
references in the code – must of course be removed before the application
should be used.
references in the code – must of course be removed before the application
should be used.
I have not done so for now. Partly because I can use the class later in the
other iterations,
I have not done so for now. Partly because I can use the class later in the
other iterations,
and partly because the reader can see how I used the log file.
and partly because the reader can see how I used the log file.
There is also reasons to warn a little against this technique, where a log file
as part of
There is also reasons to warn a little against this technique, where a log file
as part of
the development process has been used for errors. The risk is that you not
remove all
the development process has been used for errors. The risk is that you not
remove all
references in the code and then the program suddenly fails because you
refer to something that no longer exists. In this case, the class
LogFile
LogFileis a singleton, and if I delete the class, the compiler will find all
references to the class, and I can thus make sure that everything about
the log file is removed.
RIGHT TRACK
Give your career a head start
by studying with us. Experience the advantages of our collaboration with
major companies like ABB, Volvo and Ericsson!
As another thing of the same kind, the program works in that way, that
when you select SHOW to see who has won, then all cards will appear –
even for those players who have folded. This should not happen and
when all cards are shown, it is because some code in the method deal() in
the class Card5Presenter must be replaced by something else:
public void deal() {
commands.disable(true, true, true, true, true, true, true, true,
true, true); if (round == 4)
{
// for (int i = 1; i < model.getHands().size(); ++i)
// {
// if (model.getHands().get(i).isFolded()) continue;
// model.getHands().get(i).open(0);
// view.others[i].views[0].setImage(Images.getInstance().
// getImage(model.getHands().get(i).getCard(0)));
// }
for (int i = 0; i < model.getHands().size(); ++i)
{
model.getHands().get(i).open(0);
for (int j = 0; j < model.getHands().get(i).size(); ++j)
view.others[i].views[j].setImage(Images.getInstance().
getImage(model.getHands().get(i).getCard(j))); }
Again, it’s a question that I have to remember at one point to remove the bottom forAgain, it’s a
question that I have to remember at one point to remove the bottom for
loop and replace it with the code being commented out. The purpose is, of
course, that
loop and replace it with the code being commented out. The purpose is, of
course, that
in the course of the test I can keep an eye on whether players who fold, also
make it on
in the course of the test I can keep an eye on whether players who fold, also
make it on a reasonable decision.
a reasonable decision.
6.7 ITERATION 4
6.7 ITERATION 4
After the end of 3rd iteration, 5 Card Stud is in principle implemented, at least a userAfter the end
of 3rd iteration, 5 Card Stud is in principle implemented, at least a user can
play this poker variant against 4 other virtual players. In this iteration, the
following
can play this poker variant against 4 other virtual players. In this iteration,
the following
features must be implemented:
features must be implemented:
Maintenance of user accounts for each user (player) where you have to
register:
Maintenance of user accounts for each user (player) where you have to
register:
-
user name, which must uniquely identify the user
- user name, which must uniquely identify the user
-- password
password
-
balance and thus how much is in the account
- balance and thus how much is in the account
-
transactions, when and how much has been added to/used from the account,
but
- transactions, when and how much has been added to/used from the
account, but not the result of the individual rounds
not the result of the individual rounds
8989
A user can not play unless there is money on the account.
Login where players at the start of the program must identify themselves as a
player with a user name and a password. As part of the feature, it must be
possible to create a new account.
Starting a new game that is a feature that the user can choose at any time.
The function opens a dialog box where the user must select:
1. Poker variant (Card 5 Stud, Card 7 Stud, Texas Hold’em, Omaha, Card
Draw)
2. Number of players (2–6)
3. Blind (1–10, the number of chips to join a new round, default 1)
4. Start amount (the number of chips for each player, default 1000)
The program must be able to save the result for each round, where the
program for each betting round stores the cards and the bets and thus logs
the game. It has not been decided what this result should be used for, but it
could be used for some form of statistics in order to improve the behavior of
the virtual players. The function must be able to be turned on and off and
will probably be disabled as default.
Start a new game This feature is simple to implement and opens the
following dialog box:
The dialog opens either from the login window or from a button at the top of
the application window. The function can be performed at any time, and you
can therefore interrupt an ongoing round.
The implementation consists primarily of adding two classes GameView and
GamePresenter to the views layer and a few changes in the classes
MainView and MainPresenter.
User accounts
It has been decided to completely remove this feature from the program as it
does not really make any sense. The argument for the function was that if
you play poker for a long time, it might be interesting to follow if you win or
lose for a long time, but thinking about the game’s idea, it is a facility that
will hardly be used. Therefore, the program is reduced with regard to this
feature, but also because it is not really trivial to implement the feature if
you have to make sure that it also reflects the actual conditions and there are,
for example, decisions related to the function as to when to updates the
account and the program will not be interrupted without modifications are
written back to the disk.
It also means that the login function is dropping away, as the whole user
concept is thus uninteresting and thus the user (the player) will always be the
current user of the machine.
Due to this decision, this iteration is significantly reduced.
How will people travel in the future, and how will goods be transported? What resources will we use,
and how many will we need? The passenger and freight traffic sector is developing rapidly, and we
provide the impetus for innovation and movement. We develop components and systems for internal
combustion engines that operate more cleanly and more efficiently than ever before. We are also
pushing forward technologies that are bringing hybrid vehicles and alternative drives into a new
dimension – for private, corporate, and public use. The challenges are great. We deliver the solutions
and offer challenging jobs.
www.schaeffler.com/careers
JAVA 20: ABOUT THE SYSTEM DEVELOPMENT
JAVA 20: ABOUT THE SYSTEM DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT poker PROCESS: SOFTWARE DEVELOPMENT POkER
PROCESS: SOFTWARE DEVELOPMENT POkER
- -- C5 = Card 5 Stud
--- C7 = Card 7 Stud
--- TH = Texas Hold’em
--- OM = Omaha
--- CD = Card Draw
After each deal, a line is written for each player who are arranged after
their position at the table, showing the players’ cards sorted in
descending order. The colors of the cards are D (Diamonds), H (Hearts),
S (Spades) and C (Clubs), and the values of the cards are 2, 3, 4, 5, 6, 7,
8, 9, 0, J, Q, K, A. Is there 5 players the result after the 2nd deal could
be:
RQ;S7;C2
H4;S3;S2
CA;SA;DA CK;CQ;CJ D0;H7;D5
For each betting round, one line is written each time a player give a bet,
where the player’s place at the table is written, the player’s bet, how
much the player has added to the pot, the game’s new value, the player’s
amount, and the content of the pot. Note that the number of lines in a
single betting round may vary, but the result of a single line could be:
3;B1;2;4;966;19
With regard to players bets, the following terms are used:
- - B1 = BET
-- B2 = BIGBET
-- CH = CHECK
92
9292 PROCESS: SOFTWARE DEVELOPMENT
JAVA 20: ABOUT THE SYSTEM DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
PROCESS: SOFTWARE DEVELOPMENT POkER
-
FO = FOLD
- FO = FOLD
-
- FO = FOLD
- R1 = RAISE
-
- R1 = RAISE R2 = BIGRAISE
- R2 = BIGRAISE
-
- R2 = BIGRAISE
- CA = CALL
- CA = CALL
Finally, a line is written at the end of a round showing the result of the player
who has
Finally, a line is written at the end of a round showing the result of the player
who has
won. The line shows the player’s place, the hand’s value, the player’s amount after the gameFinally, a line is
written at the end of a round showing the result of the player who has
won. The line shows the player’s place, the hand’s value, the player’s
amount after the game is played and the cards. A result could be: won. The line shows
the player’s place, the hand’s value, the player’s amount after the gameis
played and the cards. A result could be:
is played and the cards. A result could be:
2;FH;1215;C3;S3;D3;SQ;DQ 2;FH;1215;C3;S3;D3;SQ;DQ
where the following abbreviations are used for the value of a hand:
where the following abbreviations are used for the value of a hand:
- SF = Straigth Flush
-- SF = Straigth Flush
-
- C4 = Four of a kind
- C4 = Four of a kind
-
- FH = Full House
- FH = Full House
-
- FL = Flush
- FL = Flush
- ST = Straight
-- ST = Straight
-
- C3 = Three of a kind
- C3 = Three of a kind
-
- TP = Two pairs
- TP = Two pairs
- C2 = One pair
-- C2 = One pair
- HC = High Card-- HC = High Card
Since the function should be disabled as default, the program is expanded by
the following Since the function should be disabled as default, the
program is expanded by the following
dialog box:
dialog box:
public Options()
{
setPath(System.getProperty("user.home") + "/pokerlog/");
}
678'<)25<2850$67(5©6'(*5((
&KDOPHUV8QLYHUVLW\RI7HFKQRORJ\FRQGXFWVUHVHDUFK
DQGHGXFDWLRQLQHQJLQHHU
LQJDQGQDWXUDOVFLHQFHVDUFKLWHFWXUHWHFKQRORJ\U
HODWHGPDWKHPDWLFDOVFLHQFHV
DQGQDXWLFDOVFLHQFHV%HKLQGDOOWKDW&KDOPHUVDFF
RPSOLVKHVWKHDLPSHUVLVWV
IRUFRQWULEXWLQJWRDVXVWDLQDEOHIXWXUH¤ERWKQDWL
RQDOO\DQGJOREDOO\
9LVLWXVRQ&KDOPHUVVHRU1H[W6WRS&KDOPHUVRQIDFHER
RN
PROCESS:
SOFTWARE DEVELOPMENTJAVA 20: ABOUT THE SYSTEM DEVELOPMENT pokerJAVA 20:
ABOUT THE SYSTEM DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
PROCESS: SOFTWARE DEVELOPMENT POkER
public final boolean isLogging()
public final boolean isLogging()
{
{
return logging.get();
return logging.get();
}
}
public final void setLogging(boolean logging)
public final void setLogging(boolean logging)
{
{
this.logging.set(logging);
this.logging.set(logging);
}
}
public final BooleanProperty loggingProperty()
public final BooleanProperty loggingProperty()
{
{
return logging;
return logging;
}
}
public final String getPath()
public final String getPath()
{
{
return path.get();
return path.get();
}
}
public final void setPath(String path)
public final void setPath(String path)
{
{
this.path.set(path);
this.path.set(path);
}
}
public final StringProperty pathProperty()
public final StringProperty pathProperty()
{
{
return path;
return path;
}
}
}
}
It’s simple to implement the log file itself using a functionality similar to
the class LogFile from the previous iteration. This class has now been
deleted and replaced by a class Logfile that contains a write method for
each of the four lines to be written:
public class Logfile
public class Logfile
{
{
private static Logfile instance;
private static Logfile instance;
95
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
private Logfile() {
}
Here you should note that the file is opened and closed for each line the
program writes to
Here you should note that the file is opened and closed for each line the
program writes to the file. The reason is that function as default is disabled,
and idea is that you only use the
the file. The reason is that function as default is disabled, and idea is that you
only use the
function if you want to collect information about the program for one reason
or another.
function if you want to collect information about the program for one reason
or another.
PROCESS: SOFTWARE DEVELOPMENT poker
Otherwise, the challenge is to get the write operations in question put in the
code in the correct places and then of course test.
You should note that to write the cards to the log the class Hand is expanded
with a single new method, which for a card returns the text to be written in
the file.
6.8 ITERATION 5
The next four iterations are similar to each other and are about to implement
another poker variant and, in principle, repeat much of the above just for
another game. I want to start with 7 Card Stud simply because this variant
looks like 5 Card Stud a lot. The most important differences are:
1. that each player has 7 cards with three closed and 4 open cards
2. that there are 5 betting rounds
3. that the players at the last two betting rounds have 6 and 7 cards
respectively to choose from
4. that it is the player with the lowest card that starts the first betting round
Scholarships
Master programmes in
Business & Economics | Behavioural Sciences | Computer Science/IT | Cultural Studies & Social
Sciences | Design | Mathematics | Natural Sciences | Technology & Engineering
-
-
Changed the class
Game
Game
poker
so it initializes the property poker with the value CARD7..
and Card7Presenter for the user interface, and for each player there is
now room for 7 cards (the number of cards to be room for has already
been implemented in the base class TableView..
I have then modified the class Card7View , so the pot moves up in the
upper left corner:
9898
PROCESS: SOFTWARE DEVELOPMENTJAVA 20: ABOUT THE SYSTEM
DEVELOPMENTpoker
PROCESS: SOFTWARE DEVELOPMENT POkER
PROCESS: SOFTWARE DEVELOPMENT POkER
Then the user interface is in principle complete.
Then the user interface is in principle complete.
As a next step, the model has been expanded with a new class Card7Player,
which so far is
As a next step, the model has been expanded with a new class
Card7Player, which so far is
just a copy of the class Card5Player. In addition, the constructor in the
class Card7Presenter
just a copy of the class Card5Player. In addition, the constructor in the
class Card7Presenter
has been changed, so it instead creates a Card7Player object. After that, the
program can
has been changed, so it instead creates a Card7Player object. After that,
the program can
run again, though it still plays 5 Card Stud, but the task is now substantially reduced
to
run again, though it still plays 5 Card Stud, but the task is now
substantially reduced to
modify the two classes Card7Player and Card7Presenter.
modify the two classes Card7Player and Card7Presenter.
As a first step, I have in the class Card7Presenter modified methods deal()
and deal1(), so I
As a first step, I have in the class , so I
As a first step, I have in the class Card7Presenter modified methods deal() and deal1(), so Ican
now deal 7 cards where the first two and the last are closed.
can now deal 7 cards where the first two and the last are closed.
The class Card7Player is extensive, as the algorithms regarding the betting
rounds needs to
The class Card7Player is extensive, as the algorithms regarding the
betting rounds needs to
be changed. Since there is now an additional betting round, the base
class AbstractPlayer is
be changed. Since there is now an additional betting round, the base class
AbstractPlayer is expanded with two abstract methods:
expanded with two abstract methods:
public abstract PokerBets
public abstract PokerBets
round5(List<Card> player, List<List<Card>> others, boolean bet, Hand
hand); round5(List<Card> player, List<List<Card>> others, boolean
bet, Hand hand);
public abstract int round6(List<Hand> hands);
public abstract int round6(List<Hand> hands);
It requires that these methods are also implemented in the class Card5Player
It requires that these methods are also implemented in the class
Card5Player
are simply implemented as trivial methods, for example.
are simply implemented as trivial methods, for example.
, where they
, where they
public int round6(List<Hand> hands)
public int round6(List<Hand> hands)
{
{throw new UnsupportedOperationException();
throw new UnsupportedOperationException();}
}
The methods that determines who will start a betting round are largely
unchanged, and
The methods that determines who will start a betting round are largely
unchanged, and
the changes primarily concerns the five methods that determines the virtual
player’s bets. the changes primarily concerns the five methods that
determines the virtual player’s bets. In principle, these methods work in
the same way as in Card5Player and are based on
to be changed, and it primarily concerns that the class now has to support 5
betting rounds.
In addition, the class is changed, so when showdown alone the 5 cards that
the player uses In addition, the class is changed, so when showdown
alone the 5 cards that the player uses are shown and as always are the
cards that give the best hand.
are shown and as always are the cards that give the best hand.
99
6.9 ITERATION 6
As the next poker variant, I will implement Texas Hold’em. Here, in the
same way as in 5 Card Stud there is 4 betting rounds, but the players can, as
in 7 Card Stud, have up to 7 cards, where the two are closed personal cards,
while the remaining 5 are open common cards on the table. The challenges
in this iteration are a bit like in the previous iteration, but such that the user
interface should be somewhat different.
In the same way as in the previous iteration, I have added the following
classes:
Then I have modified the class Game, so the default poker variant is Texas
Hold’em, and I have expanded the method initialize() in the class
MainPresenter. Then the program can run again and use as the default the
above classes. As the next step, the class TexasView has been changed, so the
user interface is as follows:
where each player now has room for 2 cards while there are room for 5 cards
on the table.
There is an additional challenge for the user interface, that in one way or
another I have to present the cards that are a player’s hand after the end of a
round. It is solved that way, that after showdown, I replace the above panel
with another panel similar to the user interface in Card7View. It’s a relatively
simple solution, which consists simply of adding another two classes:
- ResultView
- ResultPresenter
and then open the window from the method deal1().
The biggest task is the change of game algorithms in the class TexasPlayer.
The first algorithms that concern which player should start a betting round
should not be used in this variant of poker, so they are all trivial algorithms.
The other algorithms that determines a player’s bet are immediately harder
to implement appropriately, as a player this time only can see quite a few
cards. In the first betting round, the player can only see his own two closed
cards, and the rules must therefore be quite simple, quite a few and to a large
extent seem random. In the other three rounds, the player can see 5, 6 or 7
cards respectively, where 3, 4 or 5 of the cards are shared with the other
players. In the current implementations, the algorithms take into account
only which cards the current player has, but the algorithms can be improved
by also taking into account which cards the other players can get from the
open cards on the table.
6.10 ITERATION 7
The Omaha variant is basically similar to Texas Hold’em. The
implementation includes the following classes:
Next, the following classes are modified corresponding to the other variants:
1. Game
2. MainPresenter
3. OmahaPresenter, where the parameter to showResult(), that is called by
showdown, must be changed to 9
and then the program runs again, but so the program obviously still plays
Texas Hold’em. However, with regard to the user interface, there is a small
problem, because the cards in ResultView fill up too much. The biggest task,
however, is to change the game rules in the class OmahaPlayer. As for who
to start the betting rounds there are no changes, as I will apply the same rule
as for Texas Hold’em, where it is always the player after the dealer who
starts the betting. However, it is a little simplified in relation to the real
poker world, but I maintain this simple rule as it does not change anything in
relation to the current program.
In the first betting round, only two of the player’s four closed cards must be
selected, giving 6 options. For each of these 6 options, I choose the two
cards that can lead to the best hand, and on these two cards, the same
algorithm is used as in Texas Hold’em. In the second betting round, two of
the player’s closed cards must be selected, which in turn gives 6 options and
these two cards are combined with the three open cards on the table, and I
choose the combination that results in the highest hand. For this
combination, I use the same algorithm as in Texas Hold’em. The third
betting round goes the same way. There are 2 out of 4 closed cards (6 ways)
and then 3 out of 4 open cards (4 ways), giving 24 combinations. Here the
best combination is selected and the same algorithm as in Texas Hold’em is
applied to this combination. Finally, there is the fourth betting round where 3
out of 5 open cards are to be selected, what can be done in 10 ways. In this
case, there are 60 combinations, and again the hand that with the highest
value is selected.
At showdown players, who have not folded, should show the cards they have
chosen and who have won. For each player, it is enough to show 5 out of 9
cards (that’s the best hand the player can make) and thus a bit like the Texas
Hold’em variant, but this time I will show the result in a dialog box:
.
Perhaps the Texas Hold’em variation should be changed to show the result
using the same dialog box.
6.11 ITERATION 8
The last variant is 5 Card Draw, which is also the simplest variant, as there
are only two betting rounds, and since the game rules are very simple, a
player can always only see his own 5 cards. With regard to bets, I want to
use the same algorithm as in Texas Hold’em, but with slightly higher
probabilities for higher bets. In addition, the first algorithm must be
expanded so the players can decide which cards to switch. It is based on a
very simple algorithm:
These rules are simple and even too simple as it is relatively easy for the
user to figure out which cards the virtual players may have. Therefore,
the 4 last rules are changed, so the player may exchange a smaller
number of cards.
add(view, 0, 0);
getStyleClass().add("cardstyle"); setMinSize(97, 138);
setMaxSize(97, 138);
setPrefSize(97, 138);
view.addEventHandler(MouseEvent.MOUSE_CLICKED, new
EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (clickOn) {
clicked = !clicked;
if (clicked) getStyleClass().set(0, "markstyle"); else
getStyleClass().set(0, "cardstyle");
}
}
});
}
{
view.setImage(image);
}
public void clear() {
clicked = false;
getStyleClass().set(0, "cardstyle");
}
{
clickOn = true;
}
{
clickOn = false;
}
{
return clicked;
}
}
It’s a relatively big job and I want to start with a code review of the
following types:
1. The directory to be used for the application’s log file when logging the
individual game rounds.
2. Where this functionality is disabled or enabled.
It has been decided to expand with two new options. A player can
RAISE twice in the same betting round and three times in the last
betting round. It has been decided that it should be an option so that a
player at the first betting rounds can RAISE 1, 2, 3, 4 or 5 times while
the player at the last betting round can RAISE one more time. Finally, it
has been decided that the program should have the option of error
logging, and whether this feature is enabled or disabled must also be an
option.
Similarly, the class Option is expanded with two new properties:
public class Options {
and the methods are changed accordingly. Then the classes OptionsView
and OptionsPresenter and are to be adjusted, which is immediately simple.
In the view class there is not much to note but the settings must be saved
somewhere and it is decided that it should be in a file
poker.
poker. initinit in the user’s home directory and that it should be done by
simple object serialization. It has been decided that the settings should
be saved each time they are changed. However, it does have a small
problem, since JavaFX properties are not immediately serializable.
Therefore, a small class has been written that encapsulates these
properties so that you can serialize an object of this class.
public class PokerOptions implements java.io.Serializable { private
boolean errors; private boolean logging; private String path;
private int raises;
public PokerOptions() {
}
...
private Error() {
}
}writer.close();
}
catch (Exception ex)
catch (Exception ex) {
{
}
}}
}}
}
and back is just to call the method write() if the functionality is enabled.
An example
and back is just to call the method write() if the functionality is enabled. An
example
could be:
could be:
catch (Exception ex)
catch (Exception ex)
{
{if (model.getOptions().isErrors())
if (model.getOptions().isErrors())
poker.tools.Error.getInstance().write(ex.getMessage());
} poker.tools.Error.getInstance().write(ex.getMessage());
}
which is an error handling in the class OptionsPresenter. Back then, the
error handling has
which is an error handling in the class OptionsPresenter. Back then, the
error handling has to be implemented, where relevant, which happens in
connection with the following code. Back then, the error handling has
to be implemented, where relevant, which happens in connection with the
following code
review and refactoring.to be implemented, where relevant, which happens in
connection with the following code
review and refactoring.
review and refactoring.
The user interface
The user interface
The user interface
The user interface should be improved in some places (and can certainly be
improved in
The user interface should be improved in some places (and can certainly be
improved in
many places). The program, as it is now, runs well on a high resolution
display (1920 ×
many places). The program, as it is now, runs well on a high resolution
display (1920 × many places). The program, as it is now, runs well on a high
resolution display (1920 ×
1080), but on a screen with significantly lower resolution, there is no room for all the cards.1080),
but on a screen with significantly lower resolution, there is no room for all
the cards. The following is primarily about making the user interface
dependent on the current screen1080), but on a screen with significantly lower resolution,
there is no room for all the cards.
The following is primarily about making the user interface dependent on the
current screen resolution and at the same time depending on the current
variation of the game.The following is primarily about making the user
interface dependent on the current screen
resolution and at the same time depending on the current variation of the
game. resolution and at the same time depending on the current variation of
the game. 111111 PROCESS: SOFTWARE DEVELOPMENT poker
PROCESS: SOFTWARE DEVELOPMENT POkER
The program has two buttons in the top right corner of the window that
are used to open the dialog boxes for game selection and the settings.
These two buttons have I moved down to the actual game view, where
they are located to the right of the top hand.
The goal is to save a little space at the top. On the other hand, the
change must be implemented in all 5 game views. For that in the
package poker.tools, the following component has been added:
public class MenuView extends VBox
{
private Button cmdGame = new Button("New Game"); private Button
cmdPoker = new Button("Options");
Bioinformatics is the exciting field where biology, computer science, and mathematics meet.
We solve problems from biology and medicine using methods and tools from computer science and
mathematics.
Read more about this and our other international masters degree programmes at www.uu.se/master
112112
JAVA 20: ABOUT THE SYSTEM DEVELOPMENTpoker PROCESS: SOFTWARE
DEVELOPMENT POkERPROCESS: SOFTWARE DEVELOPMENT POkER
public MenuView(MainPresenter presenter)
public MenuView(MainPresenter presenter)
{
{
{super(10);
super(10);
cmdGame.setOnAction(e -> presenter.newGame(e));
cmdGame.setOnAction(e -> presenter.newGame(e));
cmdPoker.setOnAction(e -> presenter.setOptions(e));
cmdPoker.setOnAction(e -> presenter.setOptions(e));
getChildren().addAll(cmdGame, cmdPoker);
getChildren().addAll(cmdGame, cmdPoker);
cmdGame.setPrefSize(120, 30);
cmdGame.setPrefSize(120, 30);
cmdPoker.setPrefSize(120, 30);
cmdPoker.setPrefSize(120, 30);
setPadding(new Insets(10, 20, 0, 20));
}
setPadding(new Insets(10, 20, 0, 20));
}}
}
}}
Here you should first notice the parameter of the constructor, which is a
MainPresenter, so
Here you should first notice the parameter of the constructor, which is a
MainPresenter , so
that the two buttons can call event handlers in this class. In MainView, the
two original
that the two buttons can call event handlers in this class. In MainView,
the two original
buttons are removed, and the class MainPresenter is modified accordingly.
The above
buttons are removed, and the class MainPresenter is modified
accordingly. The above
component must be inserted into the 5 game views. It is resolved to add the
following
component must be inserted into the 5 game views. It is resolved to add
the following
method to the base class TableView
method to the base class TableView
protected Pane createTop(int n, MainPresenter presenter)
protected Pane createTop(int n, MainPresenter presenter) {
{{Label label = new Label();
Label label = new Label();
label.setPrefSize(160, 80);
label.setPrefSize(160, 80);
BorderPane pane =
BorderPane pane =
new BorderPane(others[n + 1], null, new MenuView(presenter), null,
label);
new BorderPane(others[n + 1], null, new MenuView(presenter), null,
label); return pane;
}
return pane;
}}
and the method is then used to insert the component into Card5View,
which is a BorderPane::
and the method is then used to insert the component into Card5View,
which is a BorderPane::
setTop(createTop(n, presenter));
setTop(createTop(n, presenter));
Then, the same change must take place in
Then, the same change must take place in
Card7View, TexasView
Card7View, , TexasView
, OmahaView and DrawView..
, , OmahaView and DrawView..
Then I have reduced the font size of the
Then I have reduced the font size of the
shows the players’ amount and the same applies to the pot. The class
Card5View has a
shows the players’ amount and the same applies to the pot. The class
Card5View has a
method called
method called and called it createPot()
createPot()
createCenter() that creates a component for the pot. This method I have
moved
createCenter() that creates a component for the pot. This method I have
moved
TextField
TextField
components (the class
components (the class
HandView ) that
HandView) that
to TableView
to TableView and called it
OmahaView and DrawView
OmahaView and DrawView
place (in the middle of the window) in all 5 variants.
place (in the middle of the window) in all 5 variants.
. Next, it must be changed in Card7View, TexasView, ,
. Next, it must be changed in Card7View, TexasView,
, and the result is that the pot is displayed alike and in the same
, and the result is that the pot is displayed alike and in the same
Each time the user selects a new game, the method newGame()Each time the user selects
a new game, the method newGame() MainPresenter
MainPresenter
the window size to the current game. What determines the size of a view
is primarily the
the window size to the current game. What determines the size of a view
is primarily the
cards, and you can reduce the window size requirements by
compressing the cards. For that
cards, and you can reduce the window size requirements by
compressing the cards. For that
reason, the class CardView is expanded with 4 static variables:
reason, the class CardView is expanded with 4 static variables:
is performed in the class
is performed in the class
. When this method is performed, a new view is created, and you can
customize
. When this method is performed, a new view is created, and you can
customize
113113
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
{
if (width < sizeX || height < sizeY)
{
CardView.width = WIDTH;
CardView.height = HEIGHT;
stage.setWidth(sizeX);
stage.setHeight(sizeY);
}
}
114
PROCESS: SOFTWARE DEVELOPMENT pokerPOkER
which is used to initialize the two static variables and calculate the
window size, where the window is represented by the last Stage object.
Both parts depend on the current screen resolution and the poker
variant to be played. The method’s first two parameters indicates the
screen resolution, while the two next indicates how much space that
view requires. The next two parameters indicates how much space is to
be used horizontally and vertically beyond the cards, and thus the
amount of space there is no need to scale and finally the next two
parameters indicates the number of cards, respectively, horizontal and
vertical. The last parameter refers to the window whose size is to be
changed.
The class MainPresenter has a method setSize() which uses the above
method to determine the window size:
private void setSize() {
CardView.reset();
int size = model.getGame().getSize();
Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
double width = bounds.getWidth(); double height =
bounds.getHeight(); if (size == 2)
{
Copenhagen Master of Excellence
Copenhagen Master of Excellence are two-year master degrees taught in
English at one of Europe’s leading universities
cultural studies
religious studies
Come to Copenhagen and aspire!
Apply now at
science
www.come.ku.dk
115115
PROCESS: SOFTWARE DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
switch (model.getGame().getPoker())
{
case CARD7:
CardView.setSize(width, height, 1070, 560, 390, 280, 7, 2, parent);
break;
case TEXAS:
case OMAHA:
CardView.setSize(width, height, 930, 735, 380, 320, 5, 3, parent);
break;
default:
parent.setWidth(930);
parent.setHeight(560);
}
}
else if (size == 3 || size == 4)
{
switch (model.getGame().getPoker())
{
case CARD7:
CardView.setSize(width, height, 1650, 680, 290, 280, 14, 3, parent);
break;
case TEXAS:
CardView.setSize(width, height, 1025, 735, 150, 320, 9, 3, parent);
break;
case OMAHA:
CardView.setSize(width, height, 1430, 735, 170, 320, 13, 3, parent);
break;
default:
CardView.setSize(width, height, 1240, 680, 270, 140, 10, 3, parent);
}
}
else
{
switch (model.getGame().getPoker())
{
case CARD7:
CardView.setSize(width, height, 1650, 850, 290, 300, 14, 4, parent);
break;
case TEXAS:
CardView.setSize(width, height, 1025, 850, 150, 300, 9, 4, parent);
break;
case OMAHA:
CardView.setSize(width, height, 1430, 850, 170, 300, 13, 4, parent);
break;
default:
CardView.setSize(width, height, 1240, 850, 270, 300, 10, 4, parent);
}
}
parent.centerOnScreen();
}
116
The method determines the size of the window based on the number of
players and thus the amount of what the cards filled up corresponding to
how many players should be presented at the table. It is divided into 2
players, 3 or 4 players and 5 or 6 players, and for each division, the size is
determined based on the current poker variant.
With the above change, the window adjusts to the current screen resolution.
If you play Omaha, the program opens a dialog at showdown, and this
dialog should be configured in the same way that it also takes into account
the screen resolution. It requires that the class OmahaPresenter has a
setSize() method similar to the above, but it is much simpler as the dialog
always displays 5 cards for each hand.
Next activity is code review combined with refactoring, and that means I’m
going through all classes and review and adjust the code. It is an extensive
work. There are 46 classes divided into 3 packages, and the following is a
brief overview of what has been done. I want to start with the classes in the
package views and the work will therefore indirectly include a test of the
application’s user interface.
The classes MainView and MainPresenter are important classes, but reverse
relatively simple classes, and the result of a review is nothing but simple
cleanup in the code. Back there are the classes for the 5 views for poker
variants, which are at the same time the key classes for the user interface.
The 5 view classes Card5View, Card7View, TexasView, OmahaView and
DrawView are all simple and there’s nothing else to do than a simple
cleanup. The same applies to the base class TableView, as methods from the
derived classes already earlier in this iteration have been moved to the base
class.
1. You can create a method in the base class with the same signature as the
current method and which implements the common code. In the sub-classes,
you can then implement an override that calls the base class method and also
has the code that the is specific for the sub-class.
Brain power
By 2020, wind could provide one-tenth of our planet’s electricity needs. Already today, SKF’s
innovative knowhow is crucial to running a large proportion of the world’s wind turbines.
Up to 25 % of the generating costs relate to maintenance. These can be reduced dramatically thanks to
our systems for on-line condition monitoring and automatic lubrication. We help make it more
economical to create cleaner, cheaper energy out of thin air.
By sharing our experience, expertise, and creativity, industries can boost performance beyond
expectations.
Therefore we need the best employees who can meet this challenge!
2. You can move the method to the base class and then add conditions that
take into account for the specific classes.
3. You can let the methods be as they are, even if that means that the same
code is duplicated.
Each option has its pros and cons, and it’s very accurate to decide what’s
right, but overall I prefer duplication of the code (and thus the last option)
rather than complicating the code (what the middle option tends to). In the
present case, I have actually applied all three options.
The 5 classes also have methods that are used only in some of the classes. If
so, one might consider moving the methods out as static methods in an
auxiliary class. The class Utils in the package poker.tools is an example of
such a class.
The result of the above refactoring is that the class TablePresenter has grown
significantly, while the 5 concrete view classes now do not fill a lot.
Then there is refactoring of the model, where there are 20 classes (types),
and here I have already at the start of this iteration carried out a review of 10
of these types. Back there are the classes:
- Model
- Hand
- AbstractPlayer
- Card5Player
- Card7Player
- TexasPlayer
- OmahaPlayer
- DrawPlayer
- Logfile
- PokerException
where there is nothing to notice about the last one. The same goes for the
class Model, which is a central class, but also a very simple class.
The class Hand is both comprehensive and important, and for the rest of the
program it is crucial that this class works correctly. In connection with code
review, nothing but ordinary cleanup has been done, but the class has a
design problem similar to a low cohesion. The problem is that the last two
variables:
- selected
- clicked
that does not make sense for all variants of poker. The first one is only used
in conjunction with Texas Hold’em and Omaha, while the latter is only used
in conjunction with CardDraw. The problems are that you can refer to the
variables in a context where they are not initialized or meaningful, and in
particular, future maintenance of the program may be more difficult. The
problem could be solved by introducing two derived classes, and then using
these classes in the current variants. In the present case, I have omitted this
change as it will mean changing some other classes and the problem solved
solely with a comment in the code.
Regarding the log file, there are also no important changes. However, a
single adjustment has been made in the method writeLine2() to support
Texas Hold’em and Omaha.
Back there are the 6 player classes
- AbstractPlayer
- Card5Player
- Card7Player
- TexasPlayer
- OmahaPlayer
- DrawPlayer
where the first is the basic class for the rest. A refactoring basically consists
of the same as above with the view classes, where methods can be moved
from the specific classes to the base class, but there are fewer methods that
can be moved this time.
Another thing is the algorithms, where there is room for improvement, but
I’ve seen only on Texas Hold’em and Omaha. As for the first one, the
algorithm looks only on the player’s own card, but does not take into
account what cards the other players can form from the cards on the table.
For example, if there are three cards on the table (what is the case in the
second betting round), each of the other players can form a hand using two
of 47 other cards (47 = 52 – the cards of the current player – the three cards
on the table). The other players have therefore
list.add(Utils.createHand(hand.getPlace(), player.get(i1),
player.get(i2),
player.get(i3), player.get(i4), player.get(i5)));
Collections.sort(list);
player = list.get(list.size() – 1).cards();
}
if (!ok) l.add(cards.getCard(j)); list.add(l);
}
}
}
double n = 0;
double n = 0;for (List<Card> lst : list) if (Hand.compare(lst,
player) < 0) ++n; return n / list.size();for (List<Card> lst : list)
if (Hand.compare(lst, player) < 0) ++n;
}return n / list.size();
}
The method returns a value between 0 and 1, and a large value (close to 1)
indicates that
The method returns a value between 0 and 1, and a large value (close to
1) indicates that
the player has good cards and therefore can bet high. With this method
available, the three
the player has good cards and therefore can bet high. With this method
available, the three
bet methods can be written differently, where the value is determined based
on the return
bet methods can be written differently, where the value is determined
based on the return
value of the above method.
value of the above method.
You can use the same strategy in connection with Omaha, just be aware that
the hand that a You can use the same strategy in connection with Omaha,
just be aware that the hand that a, just be aware that the hand that a player can form is
in another way, and that you get higher frequencies, as Omaha generally
player can form is in another way, and that you get higher frequencies,
as Omaha generally
gives results with a greater value.
gives results with a greater value.
The last thing
The last thing
The last thing
There are still a few things that are missing. Firstly, there is a test of whether
a player has
There are still a few things that are missing. Firstly, there is a test of
whether a player has
money to deposit in the pool. If this is not the case, the player must leave the
game and
money to deposit in the pool. If this is not the case, the player must leave
the game and
thus be out of the current game. In principle, it is quite simple to implement
this facility,
thus be out of the current game. In principle, it is quite simple to
implement this facility,
and it is primarily a matter of adding a variable to the Hand class:
and it is primarily a matter of adding a variable to the Hand class:
private boolean lost = false;
...private boolean lost = false;
...
{ return lost;
}return lost;
}
If a player bet and does not have chips enough, this variable is set to true
(the method setLost()
If a player bet and does not have chips enough, this variable is set to true
(the method
is called). Then the number of the player’s chips is shown as 0, and the
player
setLost() is called). Then the number of the player’s chips is shown as 0, and the playersetLost() is
called). Then the number of the player’s chips is shown as 0, and the player
folds the cards. In addition, the player in subsequent rounds must not be
assigned cards.
folds the cards. In addition, the player in subsequent rounds must not be
assigned cards.
JAVA 20: ABOUT THE SYSTEM DEVELOPMENTpokerPROCESS: SOFTWARE
DEVELOPMENT
PROCESS: SOFTWARE DEVELOPMENT POkER
If it is especially the user who has lost his chips, it has been decided that the
game is over
If it is especially the user who has lost his chips, it has been decided that the
game is over
and you get the following dialog box:
and you get the following dialog box:
After that, the user can choose to
start a new game, but closing the dialog by clicking on
After that, the user can choose to start a new game, but closing the dialog by
clicking on
the cross will close the program.
the cross will close the program.
Then there is the error logging where code should be written, that write to
the log file,
Then there is the error logging where code should be written, that write to
the log file,
and as mentioned earlier, it is important that only important information is
stored, and
and as mentioned earlier, it is important that only important information is
stored, and
that is methods as you find critical. As an example, below is shown a line
from the log file
that is methods as you find critical. As an example, below is shown a line
from the log file
(provoked by division with 0):
(provoked by division with 0):
2018:11:16: CARD5, 5, 1: class poker.views.Card5Presenter.deal1():
java.lang.ArithmeticException: / by zero
Finally, some deficiencies and forgettings have been corrected and, as
the last one, there is the installation script.