Leader Boards in Java - java

I am looking to create a leader board for work to encourage a bit of competitiveness and a general moral boost for the teams. I have created 2 pages, 1 you input data and it does a sum in the back ground for each department and then orders them.
This information should appear on the second page, the leader board itself.
My question is - is it possible to have a delayed "thinking time" for the application where the names and numbers of each department cycle quickly and load from last place to first? Kind-of like a one armed bandit machine in a casino
I am using Java SE8 in netbeans and im unsure if this is possible or if there is an alternative.

Related

What data structures can one use to implement "Ginsberg's partition search" in a game tree search?

I'm building a game tree search for a card game, similar to bridge. So I started out with building a double dummy solver for bridge. I'm trying to further optimize the current game tree search algorithm which is based on alpha-beta pruning tree search, enhanced with MTD-f https://en.wikipedia.org/wiki/MTD-f
. (All my current code is in Java)
I've been reading M.Ginsberg's paper on "partition search". It can be found in many places in the internet e.g. https://www.aaai.org/Papers/AAAI/1996/AAAI96-034.pdf
According to Ginsberg he was gaining an order of magnitude in performance by this.
After heaving read the paper multiple times, I think I more or less understand it, at least the idea is fairly simple, but working it out isn't.
I'm not sure fully understanding how the complexity of the intersection in the algorithm is avoided by doing null-window searches, although it isn't hard to see that it converts a complex problem to a binary 0 or 1 problem.
Ginsberg goes on to note in his bridge example
"although the details of the approximation functions and data structures are dependent on the rules of bridge and a discussion of their implementation is outside the scope of this paper"
I totally do not see, what sort of data structures can be used to implement this e.g. the first line of the algorithm:
if there is an entry (S,[x,y],z) with p elemOf S return (z,S)
Where
"entry" refers to an entry in some form of "transposition table"
p is a position (as one typically has it in a game tree)
S is a set of positions!
[x,y] is the possible outcome interval, similar to alpha and beta
This
somehow requires a transposition table where the keys are sets of positions?!
how does one determine elemOf?
...
Similarly for the partioning system, referred to as (P,R,C) in the paper. How does one go about building the "approximating functions" for these?
I seem unable to find implementations of this idea, data structures to support it .... Has anyone tried? Is it really worth all the effort?
P.S.
The only reference to something similar, I found, was the master thesis of S.Kupferschmid on: http://gki.informatik.uni-freiburg.de/theses/diploma_de.html
(fully in German though, and it only defines an equivalence relationship between cards that takes a Skat particularity into account. For something like bridge this is similar to "rank equivalence" i.e. if you have 6 and 4 of the same suit and the 5 of that suit was played then 6 and 4 are equivalent for the outcome of the game)

Algorithm for distributing members over activites (with individual preferences)

So in my school we have a day where everybody participates in different activities.
Each projects can have like 10 members. The whole day is divided in 2 or 3 different blocks, in which the pupils assigned to the activity change.(So in block 1 pupil x takes part in activity a and in the second block in activity d).
Before this day starts, we give make lists in which each pupil can tell us his 3 (or 4) favorite activities (he only takes part in two of them, these again are ordered from most "favorite" to least) in which he wants to take part.
Now our job is to assign these pupils in a way that we have the best overall satisfaction among the pupils (so everybody did more or less did get his/her chosen activities).What would be a good algorithm to solve this ?(I'm quite familiar with programming (especially java), so the approach would be enough too (although some (pseudo-)code would be great too:) )
Is there any way to do this, apart from calculating such a "satisfaction" value for each possible solution?
An optional feature would be that if someone can't get in to his/her project, they would get into a similar on (also this sounds kind of sexist, you could for example rate how "female"/"male" this activity is and choose similar activities according to this scale)
I'm hope this question is fits into stackexchange, if it is totally off-topic I would be happy to tell me about a more suitable stack.
Looking forward to your suggestions,
John
If the students are ranking each of their favorite activities (1-4) then it's simple to assign those activities a weight (1-4). You group everyone that weights a certain activity at a certain level and compare the number of students to the number of activities. If there's more students than spots the method of choosing is up in the air. I would say random for fairness or if you want to get fancy you can track it from day to day so that everyone gets a chance to participate in a favorite activity.
If there are more slots than students then you could poll for people who rate it a 3 and so on down the line.
That seems like a fair place to start at least.
I don't have an algorithm for you but there is a package which will do much of the job for you. The site is http://www.optaplanner.org/ and it is part of the Drools project.
Configuring the application requires some work. By the time you finish the configuration you will have gotten some hint as to how hard the task is, and why no simple algorithm will do the job.

Scrabble board to board

Is it best to communicate between two scrabble boards on separate computers by creating a cloud with a SQL table, simulating the board. And every time I move is made you contact the server and update the local board?
Sounds good to me. Scrabble doesn't require real-time millisecond precision, so using database transactions to consummate the board moves sounds like a good approach.
In your shoes, I'd try to formalize my states a bit more. If you think of it, a Scrabble game consists of:
A board
The coordinates on that board that give bonuses (x2 letter, x3 word, etal.)
The set of available letters, and the amounts of each letter available, and the point-score for each letter
A profile for each player
The set of letters in each Player's possession
The words each player has played, and where they are on the board
The player's current score
A dictionary of allowable words (for challenges)
A lot of this can be stored in an SQL database - for instance, a player's name and score. But an SQL DB might be too heavy for things like the board coordinates and how various bonuses map to various coordinates. If you think of it, these are static, read-only attributes that will never change from game to game. It might make sense to represent them as a serialized 2-D array, or something similar. Same goes for the dictionary of allowable words. In your shoes I'd be tempted to read the dictionary from a text file on server start-up, store the strings into a non-mutable array, and hand-code an ultra-fast binary search rather than suffer through the overhead of database calls to an indexed table.
Likewise the grab-bag of letters: do you really need a database for this? Maybe you do. Maybe you decide that, since the grab-bag represents mutable state that's going to be shared between all connected clients, you want to take advantage of your DB's locking mechanisms. Or maybe speed becomes an issue, so you find that an array or a list serves you better, and you're comfortable managing the thread-state yourself.
The point is that you won't know what to choose until you spell out what you're doing with some degree of precision. Then you can begin to consider the trade-offs.
Storing the board state in a central DB is fine - and good design. It's unclear how you are planning on having each client handle communications, you have a couple of options:
client 1 make a move, send details to server (persisting state in DB)
server pings client 2 notifying them that it is their move (use a remoting technology to ping)
Same as step 1 but for client 2.
Or
client 1 make a move, send details to server (persisting state in DB)
client 2 polls server until it notices that it is it's turn.
Same as step 1 but for client 2.
So, you have to consider whether you want 2-way client-server communication (client calls server, server calls client) or whether you want 1-way client server communication (clients calls server, including polling to determine when state has changed).
There are some good answers here but I would say it really all depends on what you have available. If you can assume that there is a central server available, then using it to keep track of game state would be a good idea, as it would not lock down the clients to any particular machine - they can go from one to another during the game if they wish. There would also be some extra security here, as you can detect clients that are trying to make illegal moves. And I'm sure there are other benefits too. The most obvious downside would be that this requires a server (i.e. a third piece of hardware, along with a web address and hosting, etc.).
If you can't make that assumption, there's really nothing wrong with making one client the 'server'. It just comes with different pros and cons.
As for using an SQL table, rtperson made some very good observations.

Building a Texas Hold'em playing AI..from scratch [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm interested in building a Texas Hold 'Em AI engine in Java. This is a long term project, one in which I plan to invest at least two years. I'm still at college, haven't build anything ambitious yet and wanting to tackle a problem that will hold my interest in the long term. I'm new to the field of AI. From my data structures class at college, I know basic building blocks like BFS and DFS, backtracking, DP, trees, graphs, etc. I'm learning regex, studying for the SCJP and the SCJD and I'll shortly take a (dense) statistics course.
Questions:
-Where do I get started? What books should I pick? What kind of AI do poker playing programs run on? What open source project can I take a page from? Any good AI resources in Java? I'm interested in learning Lisp as well, is Jatha good?
The following may prove useful:
The University of Alberta Computer Poker Research Group
OpenHoldem
Poker Hand Recognition, Comparison, Enumeration, and Evaluation
The Theory of Poker
The Mathematics of Poker
SpecialKPokerEval
Poker AI's are notoriously difficult to get right because humans bet unpredictably. It's usually broken into two parts.
1) Calculate the odds of your hand being the winner.
2) Formulate betting strategy based on 1.
I'd recommend starting with lots of statistics reading for part 1. It seems easy at first blush, but it's actually very complicated (and getting it wrong will doom your AI). Then move on to genetic algorithms for part 2. Betting strategies are mostly genetic algorithms. They adjust themselves based on past success and failures + some randomization so as not to become predictable.
I wrote a Texas Hold'em Video Poker engine in Java
This code is a core engine for Texas Hold'em without views and others
http://github.com/phstc/javapokertexasholdem
Also, letting genetic algorithm adjust the weights of neural network, which determines the decision logic. This approach is very suitable for poker AI.
I made my own AI like this. At first, I created ~1000 players, who didn't know how to play the game at all. Based on their initial luck during the hands, their fitness was weighted and new generation created. New "brains" were playing better than previous generation.
Eventually, the best individuals played very good.
As already recommended, the book Theory of Poker is a truly invaluable source of information for playing the game as well as for building an AI. You should probably buy it as it does not cost that much.
University of Alberta resarch group does the state-of-the-art at the moment, though they have stiff competition emerging every now and then. (Not all poker bots and AI research in the field is public because of the temptation to use one's results in internet poker, though that's forbidden.)
First you should decide what sort of poker are you going to tackle first. two player hold'em is pretty much solved, though the best humans still put up a real fight with the best AI's available. The AI has the main advantages over humans by having an unlimited flawless memory of past hands, flawless analysis of the patterns based on that and as they are machines, they don't tilt like almost all humans occasionally do.
Fixed Hold'em is probably the easiest to crack, so you might want to start with 1-1 fixed hold'em and then decide what you want to do next.
Here are some aspects which change the correct strategy (and your AI):
A cash game is different from a
tournament
-The number of players
makes the decisions different.
Hold'em
is not the only poker. Omaha, Stud
and others exist and are widely
played.
Fixed Limit is different from
Pot Limit, which is different from No
Limit.
To beat the best you need to cover a lot of very subtle things the best players think about when they play. To beat a low-stakes amateur game, none of these things count.
If you decide to go for No Limit Hold'em, you might want to check out three-book series Harrington on Hold'em and a book No Limit Poker - Theory and Practice. Having read quite a many books on poker, I can say these books combined with the Theory of Poker are quite enough.
I'm not sure which exact game you are interested in, but the typical approach is to create a much smaller abstract version of the game, solving that smaller game, and then mapping real game situations back to the abstract game to generate advice. Most of the academic papers skip over the details of this process in favor of presenting results about convergence, exploitation, and competition results.
However, there are some publicly available code bases which present a complete implementation. One of the best ones is Fell Omen:
http://www.deducer.org/pmwiki/pmwiki.php?n=Main.ArtificialIntelligencePoker
This is a basic complete strategy bot that uses fictitious play to optimize the strategy for the abstract game. It's a good starting point because it is fairly straightforward, complete, and represents a good presentation of the abstract game approach.
If you are interested in developing poker AI, I would suggest reading everything from 2007 and on from the UA poker group and Tuomas Sandholm's students:
http://www.cs.cmu.edu/~sandholm/
http://poker.cs.ualberta.ca/publications.html
I wrote a Hold'Em AI in my undergrad. It wasn't particularly advanced, I used a Q-Value machine that traversed a number of states and updated Q values for each state.
I found the University of Alberta's AI Poker project an invaluable source of info for avoiding pitfalls.
As one poster above states, the first step is to nail in a couple of determinable poker rules - one-on-one poker can be developed programatically.
One pitfall I fell into was not building in reconfigurability early on. For instance being able to switch the grade of learning/playing.
I would be interested to hear how you get on drop me a mail stevekeogh at gmail.com
Just to add to the links above, one of the important things to implement would be http://en.wikipedia.org/wiki/Kelly_criterion which will help figure out the optimal size of bets given the expected odds in a series of bets.
With humans there could be errors in judgement of odds, but if your AI program can spit the some expected normalized odds based on whatever the algorithm then this bet-sizing technique which balances both risk and reward for the advantage gambler would be a good cheap solution.
One interesting result I've heard is that if you restrict the betting options to fold, check and all-in, you can write an AI that wins one-on-ones with probability at least 49%, and 49.5% if it's (IIRC) not going first.
I don't know that this AI is easier to write that one which knows how much to bet, but it's food for thought: choosing amounts to bet only accounts for 1.5% of the probability of winning.

Simulation in java [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am novice to the simulation world, and want to learn how programmers develop real simulation projects in java. I would use eclipse.
Could anyone point to other things that I need to know (e.g. other packages, software etc. and their purposes)?
I am afraid the question might seem a bit vague as it is not clear which type of project I am talking about. But being a novice, let me say that it's to begin how to code a simulation project.
If you are building a Monte-Carlo model for a discrete event simulation or simulation model for pricing derivatives you should find there is a body of framework code already out there. If you are doing a numerical simulation such as a finite-element model you will be basing your simulation on a matrix computation library. Other types of simulation exist, but these are the two most likely cases.
I've never written a finite element model and know next to nothing about these, although I did have occasion to port one to DEC Visual FORTRAN at one point. Although the program (SAFIR, if anyone cares) was commented in French, the porting exercise consisted of modifying two date functions for a total of 6 lines of FORTRAN code - and writing a makefile.
Monte-Carlo models consist of measuring some base population to get distributions of one or more variables of interest. Then you take a Pseudo-Random number generator with good statistical and geometric properties (the Mersenne Twister algorithm is widely used for this) and write a function to convert the output of this to a random variable with the appropriate distribution. You will probably be able to find library functions that do this unless your variables have a really unusual distribution.
Then you build or obtain a simulation framework and write a routine that takes the random variables and does whatever computation you want to do for the model. You run it, storing the results of each simulation, until the error is within some desired tolerance level. After that, you calculate statistics (means, distributions etc.) from all of the runs of the simulation model.
There are quite a lot of resources on the web, and many books on simulation modelling, particularly in the area of derivatives pricing. You should hunt around and see what you can find.
As an aside, the random module on Python has conversion functions for quite a few distributions. If you want one you could get that and port the appropriate conversion function to java. You could use the output of the python one with the same random number seed to test the correctness of the java one.
Discrete-event simulation is a good option for problems that can be modeled as individual events that take place at specific times. Key activities are:
randomly generating times and durations based on empirical data, and
accumulating statistics as the simulation runs.
For example, you could simulate the activity in a parking garage as the entries and departures of a cars and the loss of customers who can't enter because the garage is full. This can be done with two model classes, a Car and the Garage, and three infrastructure classes, an Event class (described below), a Schedule to manage events, and a Monitor to accumulate data.
Here's a brief sketch of how it could work.
Event
An Event has a time, and represents calling a specific method on an object of a specific class.
Schedule
The Schedule keeps a queue of Events, ordered by Event time. The Schedule drives the overall simulation with a simple loop. As long as there are remaining Events (or until the Event that marks the end of the simulation run):
take the earliest Event from the queue,
set the "world clock" to the time of that event, and
invoke whatever action the Event specifies.
Car
The Car class holds the inter-arrival and length-of-stay statistics.
When a Car arrives, it:
logs its arrival with the Monitor,
consults the world clock, determines how long before the next Car should arrive, and posts that arrival Event on the Schedule.
asks the Garage whether it is full:
if full, the Car logs its departure as a lost customer with the Monitor.
if not full, the Car:
logs its entry with the Monitor,
tells the Garage it has entered (so that the Garage can decrease its available capacity),
determines how long it will stay, and posts its departure Event with the Schedule.
When a Car departs, it:
tells the Garage (so the Garage can increase available capacity), and
logs its departure with the Monitor.
Garage
The Garage keeps track of the Cars that are currently inside, and knows about its available capacity.
Monitor
The Monitor keeps track of the statistics in which you're interested: number of customers (successfully-arriving Cars), number of lost customers (who arrived when the lot was full), average length of stay, revenue (based on rate charged for parking), etc.
A simulation run
Start the simulation by putting two Events into the schedule:
the arrival of the first Car (modeled by instantiating a Car object and calling its "arrive" event) and
the end of the simulation.
Repeat the basic simulation loop until the end-of-simulation event is encountered. At that point, ask the Garage to report on its current occupants, and ask the Monitor to report the overall statistics for the session.
The short answer is that it depends.
Unless you can make the question more specific, there is no way to give an answer.
What do you want to simulate?
For example, if you want to simulate adding two numbers, you can do it using something like:
a = b + c;
If you want to simulate the bouncing of a ball, you can do that using a little bit of math equations and the graphic libraries.
If you want to simulate a web browser, you can do that too.
So the exact answer depends on what simulation you want to do.
Come up with a problem first.
There's no such things as a generic "simulation". There are lots of techniques out there.
If you're just a gamer who wants to have pseudo-physics, maybe something like this would be what you had in mind.
Have a look at Repast Symphony: http://repast.sourceforge.net/repast_simphony.html
"Repast Simphony 2.0 Beta, released on 12/3/2010, is a tightly integrated, richly interactive, cross platform Java-based modeling system that runs under Microsoft Windows, Apple Mac OS X, and Linux. It supports the development of extremely flexible models of interacting agents for use on workstations and small computing clusters. 
Repast Simphony models can be developed in several different forms including the ReLogo
 dialect of Logo, point-and-click flowcharts, Groovy, or Java, all of which can be fluidly interleaved NetLogo
 models can also be imported.
Repast Simphony has been successfully used in many application domains including social science, consumer products, supply chains, possible future hydrogen infrastructures
, and ancient pedestrian traffico name a few."
This is an old question, but for Simulation in Java I just installed and tested JavaSim by
Mark Little, University of Newcastle upon Tyne. As far as I can tell, it works very well if you have a model you can convert into a discrete event simulation. See Mark's site http://markclittle.blogspot.com.au/2008/03/csimjavasim.html. I also attempted to use Desmo-J, which is very extensive and has a 2-D graphical mode, but could not get it going under JDK 1.6 on a Mac.

Categories

Resources