Java multiplayer card game AI integration - java

I have developed a Multi-player Client/Server Variation of Trumps Card Game using QuickServer library. It works well with 4 human players. But when I finished the AI player, I didn't find a way to integrate it into the server: Should I create a separate thread for each player?
I hope my question is clear. Any suggestions would be highly appreciated.

A server should just be a server. In this case, it updates the clients as to what happened and what happens next.
If it were me, I would have a AIClientPlayer, which gets passed a client, and acts using your fancy AI logic when the client signals it to act.

Related

Android Java listener for variable on Spring Boot server change

Hello I am wondering if this is possible to notify Android with some kind of listener the best via Retrofit when variable on server side change (to be specific concrete record on database shows up)?
Or you have any other ideas how can I achieve that with the simplest way.
The use case is that: I am developing Android RPG game. There are players that can fight with each other. They are all located on world map and you can choose the player you want to fight with. And now I want to get information in code once I am attacked or inform another player that he is attacked and open a new arena map dedicated for PvP fighting.
Currently I do it by retrofit call to server that checks if that record in database exists every few seconds but I guess it is not the best solution, as some people can have various internet limitations.
Kind regards.
Check out web sockets. They behave as you need.

How to add multiplayer in Android?

I'm making a Tic Tac Toe game in Android with three options:One player, two players and multiplayer.
The first two options were easy to make but I'm having A LOT of troubles with the last one, I have no idea what to do.
I am a beginner java programmer and I've never worked on networking with java, I know some basic things like MySQL and web stuff but I dont think it has anything to do with android.
So my questions are:
Do I have to use a server for this type of game? how and where do I find servers for this?
What do I need to learn in order to have the knowledge for developing multiplayer games?
Is it possible to make players play with other random available players? just hit play and be ready to go.
Can you recommend me some good guides that could help me?
Thank you very much !
Try Firebase
Firebase can act as a server where the users are connected
Firebase provides Realtime Database which would help your app. for eg
when a player makes a move, the changes would be effected to all the other player devices in Realtime by Firebase itself, you won't have to write the code to keep them in Sync
I recommend you take a look at Google Play Games Services.
It comes with a tone of features, and, most important for you, it has a Turn Based Multiplayer option that you could maybe use in your Tic Tac Toe.

Java Tic Tac Toe architecture

I'm currently having a major brain fart :).
My plan was to build a simple swing based tic tac toe application in Java. I had planned for the app to allow for one player, two player local and two player remote options. I've got the one and two player local versions working fine but am struggling to get my head around the two player remote option.
Worth noting in the Netbeans project I have the gui in a separate package from the logic.
I've fried my brain thinking about all the options.
Like having a client server architecture but then if the client is running on a different pc than the logic this slows down the one player and two player local versions for no reason.
I'm thinking the entire application (gui + logic) should be distributed amongst the various pc's on the home wirless network. That way players can play one and two player local games without any unneccesary lag time and see if anyone else is available for a two player remote version. The question if I go this way is who's logic acts as the server - how does that work?
Is option 2 the best / only way of going about this because this isn't just a networked game?
Are there any other ways of going about this?
I know doing a tic tac toe game with just a remote game option would be a simple case of a client server architecture but having one player and then a networked version in the same app is tricky.
Thanks,
Paul.
Technically, you could do this without actual server -- you can make it like client/host.
When user wants to be host, he sends UDP broadcast packet, with information on what ip, and what game he wants to play. everyone who wants to join can catch this packet.
When user wants to join, he listens to broadcast packet, and joins to the one he recieved.
Every player could do his own logic, and send his move to other player -- other side should only check is the move legal -- because maybe someone wants to hack your game :D
The application should be installed on each client. For the remote 2-player mode, you should implement your own P2P protocol to send actions from one player to the other and to keep track of the evolution of the game.
In a few words, each client should have its own model of the game locally which it updates whenever either the local player makes "a move" or the remote user sends (through the protocol) "a move".
Of course, if you need to keep track of statistics like scores, points, etc, you will need a central server to store this. But the actual game should take place in a P2P mode, with no need for a server.

Java Server Options

I want to make a browser-based game in Java that will depend heavily on networking. I wanted to make it so that one player in the game hosts it and the rest in that game play with him, but with Java that requires signing the applet and port forwarding and all kinds of stuff.
So my question is, What would be the best way to design a server system for my game without
spending tons of money on 24/7 server hosting? If I didn't explain parts of my question well enough, please tell me and I will reword it. Thanks in advance!
A Java Applet is not a strictly 'browser-based' game because it will require the JRE.
If you're intent on Java, you might look in the Google Web Toolkit. It allows you to write client and server code entirely in Java and compile it to JavaScript. I'd caution that it has a steep learning curve especially if you aren't familiar with servlets and client-server programming in general.
Here's an example game made in GWT:
http://allen-sauer.com/com.allen_sauer.gwt.game.hornetblast.HornetBlast/HornetBlast.html
As for server hosting, if you don't want to purchase/maintain your own server, you might consider a cloud provider such as Amazon Elastic Compute Cloud (EC2). A single instance will run you $40-$70 per month.
My first guess would be to make the game peer-2-peer , so that a server is not involved except for downloading the game. When the game starts, have it prompt for the IP addresses of your friends. This could be sortof a password into the game to get it started.
Some thoughts/ideas:
http://java.sun.com/developer/technicalArticles/peer/
http://code.google.com/p/jsmpp/
http://www.ibm.com/developerworks/java/library/j-jxta2/

Creating a virtual world with Red5

I'm thinking about creating a virtual world using the open source socket server 'Red5'.
I know that i'd have to develop a custom adapter/addin to make it suitable for a virtual world. but am unsure where to start. I have a good knowledge of java.
I've never done a virtual world, but where a project like this would start for me is designing the world roughly (on paper). What happens when a client connects, what happens when the client disconnects/drops suddenly, what data is persistent and so on. Then designing how the clients communicate with the server and with each other (ie. the protocol). Presumably if you are planning on using RED5 this would be a centralised thing not a P2P one. Once you have the protocol designed on paper you can code it up and see what you've missed -> iteration number 2. Depending on how much experience you have on stuff like this you'll need to do 2-10 iterations of the communications.
For the design state I would look at game engines and see what they provide in terms of distributed play. I'd imagine that you'll want to use a game engine to render the stuff so you'll need one anyway.
If you've never done stuff like this before, it might be worthwhile to make a little game just to see what are the things you need to take into account. Like a multiplayer pong for instance. Although the realtime constraints on pong are slightly different to those of a virtual world (at least if there is no one driving around at 200 km/h in the world).

Categories