This sample demonstrates a Web-based Tic-tac-toe game.
The game is implemented as a single project, TicTacToe.csproj, which uses the .NET Generic Host to host an ASP.NET Core MVC application alongside Orleans.
The client side of the game is a JavaScript application which polls the MVC application for updates. MVC controllers forward requests on to grains. The application has 3 types of grains:
PlayerGrainwhich represents a player, allowing the caller to join and leave games, update properties, and retrieve an overview of the past and present games.GameGrainwhich represents an individual game session and the accompanying game logic.GameGrainallows clients to make moves and see current game board state.PairingGrainwhich holds a list of the currently available games which other players can join.
The call flow is as follows:
Open a terminal window and execute the following at the command prompt:
dotnet run The game server will start and you can open a browser to http://localhost:5000/ to interact with the game.
If you wish, you can start more instances of the host to see them form a cluster. If you do so, add the InstanceId option on the command line to differentiate them. A production application would use something other than the "localhost clustering" which this application uses (see Program.cs for where clustering is configured via UseLocalhostClustering) and therefore this InstanceId option would not be necessary.
dotnet run -- --InstanceId 1Since the game uses cookies to identify players, you will need a separate browser session in order to be able to play against yourself and experience the game.

