├── Source ├── Web │ └── OnlineGames.Web.AiPortal │ │ ├── Views │ │ ├── _ViewStart.cshtml │ │ ├── Shared │ │ │ ├── Error.cshtml │ │ │ ├── _LoginPartial.cshtml │ │ │ └── _Layout.cshtml │ │ ├── Upload │ │ │ └── Index.cshtml │ │ ├── Uploads │ │ │ └── All.cshtml │ │ ├── Battles │ │ │ ├── Info.cshtml │ │ │ └── All.cshtml │ │ ├── Account │ │ │ └── LoginWithTelerikAcademy.cshtml │ │ ├── Home │ │ │ └── Index.cshtml │ │ ├── Competitions │ │ │ └── Info.cshtml │ │ ├── Web.config │ │ └── Teams │ │ │ ├── Create.cshtml │ │ │ └── Info.cshtml │ │ ├── favicon.ico │ │ ├── Global.asax │ │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ │ ├── Scripts │ │ └── _references.js │ │ ├── Controllers │ │ ├── BaseController.cs │ │ ├── AdminDashboardController.cs │ │ ├── UploadsController.cs │ │ ├── HomeController.cs │ │ ├── BattlesController.cs │ │ ├── CompetitionsController.cs │ │ └── AccountController.cs │ │ ├── Infrastructure │ │ ├── Mapping │ │ │ ├── IHaveCustomMappings.cs │ │ │ ├── IMapFrom{T}.cs │ │ │ └── AutoMapperConfig.cs │ │ ├── PrincipalExtensions.cs │ │ ├── AiPortalPrincipal.cs │ │ └── AiPortalUserData.cs │ │ ├── Startup.cs │ │ ├── App_Start │ │ ├── FilterConfig.cs │ │ ├── RouteConfig.cs │ │ ├── BundleConfig.cs │ │ └── NinjectWebCommon.cs │ │ ├── ViewModels │ │ ├── Home │ │ │ ├── IndexViewModel.cs │ │ │ └── IndexCompetitionViewModel.cs │ │ ├── Teams │ │ │ ├── UploadViewModel.cs │ │ │ ├── TeamBattleViewModel.cs │ │ │ ├── TeamInfoViewModel.cs │ │ │ ├── CreateTeamViewModel.cs │ │ │ └── TeamMemberViewModel.cs │ │ ├── Battles │ │ │ ├── BattleGameResultViewModel.cs │ │ │ ├── BattleInfoViewModel.cs │ │ │ └── BattleSimpleInfoViewModel.cs │ │ ├── Upload │ │ │ ├── FileUploadInputModel.cs │ │ │ └── UploadInListViewModel.cs │ │ ├── Account │ │ │ └── ExternalLoginViewModel.cs │ │ └── Competitions │ │ │ └── CompetitionViewModel.cs │ │ ├── Content │ │ └── Site.css │ │ ├── Web.Debug.config │ │ ├── Web.Release.config │ │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ └── PublishProfiles │ │ │ ├── 78.128.6.6.pubxml │ │ │ └── TelerikAcademyServer.pubxml │ │ ├── Global.asax.cs │ │ └── packages.config ├── Workers │ └── OnlineGames.Workers.BattlesSimulator │ │ ├── BatchFiles │ │ ├── StopService.bat │ │ └── InstallService.bat │ │ ├── GamesExecutors │ │ ├── SantasePlayerDirector.cs │ │ ├── GameSimulationException.cs │ │ ├── IGamesExecutor.cs │ │ ├── BaseGamesExecutor.cs │ │ ├── SantaseGamesExecutor.cs │ │ ├── TexasHoldemGamesExecutor.cs │ │ └── TexasHoldemPlayerDirector.cs │ │ ├── IJob.cs │ │ ├── packages.config │ │ ├── GamesSimulator │ │ ├── IGamesSimulator.cs │ │ ├── SingleGameResult.cs │ │ ├── GamesSimulatorResult.cs │ │ └── GamesSimulator.cs │ │ ├── Program.cs │ │ ├── BattlesSimulatorServiceInstaller.cs │ │ ├── SynchronizedHashtable.cs │ │ ├── Settings.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── App.config │ │ └── BattlesSimulatorService.cs ├── OnlineGames.Common │ ├── packages.config │ ├── GlobalConstants.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── OnlineGames.Common.csproj ├── Data │ ├── OnlineGames.Data.Common │ │ ├── packages.config │ │ ├── App.config │ │ ├── Models │ │ │ ├── IOrderable.cs │ │ │ ├── IAuditInfo.cs │ │ │ ├── IDeletableEntity.cs │ │ │ └── BaseModel{TKey}.cs │ │ ├── IDbRepository{T}.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── DbRepository{T}.cs │ │ └── OnlineGames.Data.Common.csproj │ ├── OnlineGames.Data │ │ ├── packages.config │ │ ├── Migrations │ │ │ ├── 201511291330516_GamesExecutorClassName.cs │ │ │ ├── 201511282136457_Battles.Designer.cs │ │ │ ├── 201511232031160_FileUploads.Designer.cs │ │ │ ├── 201510221601215_InitialCreate.Designer.cs │ │ │ ├── 201511291330516_GamesExecutorClassName.Designer.cs │ │ │ ├── 201511232031160_FileUploads.cs │ │ │ ├── Configuration.cs │ │ │ └── 201511282136457_Battles.cs │ │ ├── App.config │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── AiPortalDbContext.cs │ └── OnlineGames.Data.Models │ │ ├── packages.config │ │ ├── BattleGameWinner.cs │ │ ├── UserProvider.cs │ │ ├── TeamMember.cs │ │ ├── BattleGameResult.cs │ │ ├── Role.cs │ │ ├── Upload.cs │ │ ├── App.config │ │ ├── User.cs │ │ ├── Team.cs │ │ ├── Battle.cs │ │ ├── Competition.cs │ │ └── Properties │ │ └── AssemblyInfo.cs ├── Services │ └── OnlineGames.Services.AiPortal │ │ ├── Uploads │ │ ├── LibraryValidators │ │ │ ├── ILibraryValidator.cs │ │ │ ├── LibraryValidatorResult.cs │ │ │ ├── TexasHoldemLibraryValidator.cs │ │ │ └── SantaseLibraryValidator.cs │ │ ├── IUploadFileValidator.cs │ │ ├── UploadFileValidatorResult.cs │ │ └── UploadFileValidator.cs │ │ ├── IRemoteDataService.cs │ │ ├── packages.config │ │ ├── Models │ │ └── CheckUserLoginApiModel.cs │ │ ├── Battles │ │ ├── IBattlesGenerator.cs │ │ └── BattlesGenerator.cs │ │ ├── App.config │ │ ├── Sandbox.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ └── RemoteDataService.cs ├── stylecop.json ├── Settings.StyleCop ├── .gitignore └── Rules.ruleset ├── Assets └── AiPortal │ └── Icons │ ├── favicon.ico │ ├── apple-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── favicon-96x96.png │ ├── ms-icon-70x70.png │ ├── apple-icon-57x57.png │ ├── apple-icon-60x60.png │ ├── apple-icon-72x72.png │ ├── apple-icon-76x76.png │ ├── ms-icon-144x144.png │ ├── ms-icon-150x150.png │ ├── ms-icon-310x310.png │ ├── android-icon-36x36.png │ ├── android-icon-48x48.png │ ├── android-icon-72x72.png │ ├── android-icon-96x96.png │ ├── apple-icon-114x114.png │ ├── apple-icon-120x120.png │ ├── apple-icon-144x144.png │ ├── apple-icon-152x152.png │ ├── apple-icon-180x180.png │ ├── android-icon-144x144.png │ ├── android-icon-192x192.png │ ├── apple-icon-precomposed.png │ ├── browserconfig.xml │ ├── manifest.json │ └── README.md ├── appveyor.yml ├── README.md └── LICENSE /Source/Web/OnlineGames.Web.AiPortal/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/BatchFiles/StopService.bat: -------------------------------------------------------------------------------- 1 | NET STOP "AI Battles Simulator Service" 2 | pause -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/favicon.ico -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/favicon-16x16.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/favicon-32x32.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/favicon-96x96.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/ms-icon-70x70.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/ms-icon-70x70.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-57x57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-57x57.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-60x60.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-72x72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-72x72.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-76x76.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/ms-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/ms-icon-144x144.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/ms-icon-150x150.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/ms-icon-150x150.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/ms-icon-310x310.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/ms-icon-310x310.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/android-icon-36x36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/android-icon-36x36.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/android-icon-48x48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/android-icon-48x48.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/android-icon-72x72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/android-icon-72x72.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/android-icon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/android-icon-96x96.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-114x114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-114x114.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-120x120.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-144x144.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-152x152.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-180x180.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/android-icon-144x144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/android-icon-144x144.png -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/android-icon-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/android-icon-192x192.png -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Source/Web/OnlineGames.Web.AiPortal/favicon.ico -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/apple-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Assets/AiPortal/Icons/apple-icon-precomposed.png -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="OnlineGames.Web.AiPortal.MvcApplication" Language="C#" %> 2 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | os: Visual Studio 2015 3 | before_build: 4 | - ps: nuget restore Source\OnlineGames.sln 5 | build: 6 | verbosity: minimal -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NikolayIT/GameAITesterOnline/HEAD/Source/Web/OnlineGames.Web.AiPortal/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /Source/OnlineGames.Common/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GameAITesterOnline 2 | Web portal for determining the best AI players for games 3 | 4 | ## Build status 5 | 6 | [![Build status](https://ci.appveyor.com/api/projects/status/pa7ox3tdq064u84y?svg=true)](https://ci.appveyor.com/project/NikolayIT/gameaitesteronline) 7 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model HandleErrorInfo 2 | 3 | @{ 4 | ViewBag.Title = "Error"; 5 | } 6 | 7 |

Error.

8 |

An error occurred while processing your request.

9 |
@Model.Exception
-------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/browserconfig.xml: -------------------------------------------------------------------------------- 1 | 2 | #ffffff -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Scripts/_references.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/BatchFiles/InstallService.bat: -------------------------------------------------------------------------------- 1 | NET STOP "AI Battles Simulator Service" 2 | sc delete "AI Battles Simulator Service" 3 | timeout 10 4 | CD %~dp0 5 | C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil "..\OnlineGames.Workers.BattlesSimulator.exe" 6 | NET START "AI Battles Simulator Service" 7 | pause -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/Models/IOrderable.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Common.Models 7 | { 8 | public interface IOrderable 9 | { 10 | int OrderBy { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/SantasePlayerDirector.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using Santase.Logic.Players; 9 | } 10 | -------------------------------------------------------------------------------- /Source/OnlineGames.Common/GlobalConstants.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Common 7 | { 8 | public static class GlobalConstants 9 | { 10 | public const string AdministratorRoleName = "Administrator"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/BattleGameWinner.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | public enum BattleGameWinner 9 | { 10 | Draw = 0, 11 | First = 1, 12 | Second = 2 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/BaseController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System.Web.Mvc; 9 | 10 | public class BaseController : Controller 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/UserProvider.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | public enum UserProvider 9 | { 10 | // LocalUser = 0, => Not implemented, yet. 11 | TelerikAcademyUser = 1, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/IJob.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator 7 | { 8 | public interface IJob 9 | { 10 | string Name { get; set; } 11 | 12 | void Start(); 13 | 14 | void Stop(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/Models/IAuditInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Common.Models 7 | { 8 | using System; 9 | 10 | public interface IAuditInfo 11 | { 12 | DateTime CreatedOn { get; set; } 13 | 14 | DateTime? ModifiedOn { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/Models/IDeletableEntity.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Common.Models 7 | { 8 | using System; 9 | 10 | public interface IDeletableEntity 11 | { 12 | bool IsDeleted { get; set; } 13 | 14 | DateTime? DeletedOn { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Infrastructure/Mapping/IHaveCustomMappings.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Infrastructure.Mapping 7 | { 8 | using AutoMapper; 9 | 10 | public interface IHaveCustomMappings 11 | { 12 | void CreateMappings(IConfiguration configuration); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Infrastructure/Mapping/IMapFrom{T}.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Infrastructure.Mapping 7 | { 8 | // ReSharper disable once UnusedTypeParameter (used in the reflection code when creating Automapper mappings) 9 | public interface IMapFrom 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/LibraryValidators/ILibraryValidator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads.LibraryValidators 7 | { 8 | using System.Reflection; 9 | 10 | public interface ILibraryValidator 11 | { 12 | LibraryValidatorResult Validate(Assembly assembly); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Startup.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using Microsoft.Owin; 7 | using Owin; 8 | 9 | [assembly: OwinStartupAttribute(typeof(OnlineGames.Web.AiPortal.Startup))] 10 | 11 | namespace OnlineGames.Web.AiPortal 12 | { 13 | public class Startup 14 | { 15 | public void Configuration(IAppBuilder app) 16 | { 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesSimulator/IGamesSimulator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesSimulator 7 | { 8 | public interface IGamesSimulator 9 | { 10 | GamesSimulatorResult SimulateGames(byte[] firstAssemblyAsBytes, byte[] secondAssemblyAsBytes, string gamesExecutorClassName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Source/stylecop.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", 3 | "settings": { 4 | "layoutRules": { 5 | "newlineAtEndOfFile": "require" 6 | }, 7 | "namingRules": { 8 | "allowCommonHungarianPrefixes": true 9 | }, 10 | "documentationRules": { 11 | "companyName": "Nikolay Kostov (Nikolay.IT)", 12 | "copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\r\nLicensed under the MIT License. See LICENSE in the project root for license information." 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/IRemoteDataService.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal 7 | { 8 | using System.Threading.Tasks; 9 | 10 | using OnlineGames.Services.AiPortal.Models; 11 | 12 | public interface IRemoteDataService 13 | { 14 | Task Login(string username, string password); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/App_Start/FilterConfig.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal 7 | { 8 | using System.Web.Mvc; 9 | 10 | public static class FilterConfig 11 | { 12 | public static void RegisterGlobalFilters(GlobalFilterCollection filters) 13 | { 14 | filters.Add(new HandleErrorAttribute()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/GameSimulationException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using System; 9 | 10 | public class GameSimulationException : Exception 11 | { 12 | public GameSimulationException(string message) 13 | : base(message) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/TeamMember.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using OnlineGames.Data.Common.Models; 9 | 10 | public class TeamMember : BaseModel 11 | { 12 | public int TeamId { get; set; } 13 | 14 | public virtual Team Team { get; set; } 15 | 16 | public int UserId { get; set; } 17 | 18 | public virtual User User { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Models/CheckUserLoginApiModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Models 7 | { 8 | public class CheckUserLoginApiModel 9 | { 10 | public bool IsValid { get; set; } 11 | 12 | public string UserName { get; set; } 13 | 14 | public string SmallAvatarUrl { get; set; } 15 | 16 | public bool IsAdmin { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/BattleGameResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using OnlineGames.Data.Common.Models; 9 | 10 | public class BattleGameResult : BaseModel 11 | { 12 | public int BattleId { get; set; } 13 | 14 | public virtual Battle Battle { get; set; } 15 | 16 | public string Report { get; set; } 17 | 18 | public BattleGameWinner BattleGameWinner { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/AdminDashboardController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System.Web.Mvc; 9 | 10 | using OnlineGames.Common; 11 | 12 | [Authorize(Roles = GlobalConstants.AdministratorRoleName)] 13 | public class AdminDashboardController : Controller 14 | { 15 | public ActionResult Index() 16 | { 17 | return null; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/Role.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using System.Collections.Generic; 9 | 10 | using OnlineGames.Data.Common.Models; 11 | 12 | public class Role : BaseModel 13 | { 14 | public Role() 15 | { 16 | this.Users = new HashSet(); 17 | } 18 | 19 | public string Name { get; set; } 20 | 21 | public virtual ICollection Users { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Infrastructure/PrincipalExtensions.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Infrastructure 7 | { 8 | using System.Security.Principal; 9 | 10 | using OnlineGames.Common; 11 | 12 | public static class PrincipalExtensions 13 | { 14 | public static bool IsAdmin(this IPrincipal principal) 15 | { 16 | return principal.IsInRole(GlobalConstants.AdministratorRoleName); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Home/IndexViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Home 7 | { 8 | using System.Collections.Generic; 9 | 10 | using OnlineGames.Web.AiPortal.ViewModels.Teams; 11 | 12 | public class IndexViewModel 13 | { 14 | public IEnumerable CurrentUserTeams { get; set; } 15 | 16 | public IEnumerable ActiveCompetitions { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/IGamesExecutor.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using System.Collections.Generic; 9 | using System.Reflection; 10 | 11 | using OnlineGames.Workers.BattlesSimulator.GamesSimulator; 12 | 13 | public interface IGamesExecutor 14 | { 15 | IEnumerable SimulateGames(Assembly firstAssembly, Assembly secondAssembly, int count); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/Upload.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using System.ComponentModel.DataAnnotations; 9 | 10 | using OnlineGames.Data.Common.Models; 11 | 12 | public class Upload : BaseModel 13 | { 14 | public int TeamId { get; set; } 15 | 16 | public virtual Team Team { get; set; } 17 | 18 | public string FileName { get; set; } 19 | 20 | [Required] 21 | public byte[] FileContents { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Home/IndexCompetitionViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Home 7 | { 8 | using OnlineGames.Data.Models; 9 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 10 | 11 | public class IndexCompetitionViewModel : IMapFrom 12 | { 13 | public int Id { get; set; } 14 | 15 | public string Name { get; set; } 16 | 17 | public string Description { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Teams/UploadViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Teams 7 | { 8 | using System; 9 | 10 | using OnlineGames.Data.Models; 11 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 12 | 13 | public class UploadViewModel : IMapFrom 14 | { 15 | public int Id { get; set; } 16 | 17 | public DateTime CreatedOn { get; set; } 18 | 19 | public string FileName { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Battles/BattleGameResultViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Battles 7 | { 8 | using OnlineGames.Data.Models; 9 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 10 | 11 | public class BattleGameResultViewModel : IMapFrom 12 | { 13 | public int Id { get; set; } 14 | 15 | public string Report { get; set; } 16 | 17 | public BattleGameWinner BattleGameWinner { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Upload/FileUploadInputModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Upload 7 | { 8 | using System.ComponentModel.DataAnnotations; 9 | using System.Web; 10 | 11 | public class FileUploadInputModel 12 | { 13 | public int Id { get; set; } 14 | 15 | // TODO: Add URL validation 16 | [Required] 17 | public string SourceCodeRepository { get; set; } 18 | 19 | public HttpPostedFileBase AiFile { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Account/ExternalLoginViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Account 7 | { 8 | using System.ComponentModel.DataAnnotations; 9 | 10 | public class ExternalLoginViewModel 11 | { 12 | [Required] 13 | [Display(Name = "User name")] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | [DataType(DataType.Password)] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesSimulator/SingleGameResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesSimulator 7 | { 8 | using OnlineGames.Data.Models; 9 | 10 | public class SingleGameResult 11 | { 12 | public SingleGameResult(BattleGameWinner winner, string report) 13 | { 14 | this.Winner = winner; 15 | this.Report = report; 16 | } 17 | 18 | public BattleGameWinner Winner { get; } 19 | 20 | public string Report { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201511291330516_GamesExecutorClassName.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Migrations 7 | { 8 | using System.Data.Entity.Migrations; 9 | 10 | public partial class GamesExecutorClassName : DbMigration 11 | { 12 | public override void Up() 13 | { 14 | this.AddColumn("dbo.Competitions", "GamesExecutorClassName", c => c.String()); 15 | } 16 | 17 | public override void Down() 18 | { 19 | this.DropColumn("dbo.Competitions", "GamesExecutorClassName"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/IUploadFileValidator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads 7 | { 8 | using System.IO; 9 | 10 | using OnlineGames.Services.AiPortal.Uploads.LibraryValidators; 11 | 12 | public interface IUploadFileValidator 13 | { 14 | UploadFileValidatorResult ValidateFile( 15 | string fileName, 16 | int contentLength, 17 | Stream inputStream, 18 | ILibraryValidator libraryValidator); 19 | 20 | ILibraryValidator CreateLibraryValidator(string fullClassName); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/LibraryValidators/LibraryValidatorResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads.LibraryValidators 7 | { 8 | public class LibraryValidatorResult 9 | { 10 | public LibraryValidatorResult(string error) 11 | { 12 | this.IsValid = false; 13 | this.Error = error; 14 | } 15 | 16 | public LibraryValidatorResult() 17 | { 18 | this.IsValid = true; 19 | } 20 | 21 | public bool IsValid { get; } 22 | 23 | public string Error { get; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Battles/IBattlesGenerator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Battles 7 | { 8 | using OnlineGames.Data.Common; 9 | using OnlineGames.Data.Models; 10 | 11 | public interface IBattlesGenerator 12 | { 13 | int GenerateBattles(IDbRepository teamsRepository, IDbRepository battlesRepository, int competitionId); 14 | 15 | int RestartBattlesForCompetition(IDbRepository battlesRepository, int competitionId); 16 | 17 | void RestartBattlesForTeam(IDbRepository battlesRepository, int teamId); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/App_Start/RouteConfig.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal 7 | { 8 | using System.Web.Mvc; 9 | using System.Web.Routing; 10 | 11 | public static class RouteConfig 12 | { 13 | public static void RegisterRoutes(RouteCollection routes) 14 | { 15 | routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 16 | 17 | routes.MapRoute( 18 | name: "Default", 19 | url: "{controller}/{action}/{id}", 20 | defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "App", 3 | "icons": [ 4 | { 5 | "src": "\/android-icon-36x36.png", 6 | "sizes": "36x36", 7 | "type": "image\/png", 8 | "density": "0.75" 9 | }, 10 | { 11 | "src": "\/android-icon-48x48.png", 12 | "sizes": "48x48", 13 | "type": "image\/png", 14 | "density": "1.0" 15 | }, 16 | { 17 | "src": "\/android-icon-72x72.png", 18 | "sizes": "72x72", 19 | "type": "image\/png", 20 | "density": "1.5" 21 | }, 22 | { 23 | "src": "\/android-icon-96x96.png", 24 | "sizes": "96x96", 25 | "type": "image\/png", 26 | "density": "2.0" 27 | }, 28 | { 29 | "src": "\/android-icon-144x144.png", 30 | "sizes": "144x144", 31 | "type": "image\/png", 32 | "density": "3.0" 33 | }, 34 | { 35 | "src": "\/android-icon-192x192.png", 36 | "sizes": "192x192", 37 | "type": "image\/png", 38 | "density": "4.0" 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/Models/BaseModel{TKey}.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Common.Models 7 | { 8 | using System; 9 | using System.ComponentModel.DataAnnotations; 10 | using System.ComponentModel.DataAnnotations.Schema; 11 | 12 | public abstract class BaseModel : IAuditInfo, IDeletableEntity 13 | { 14 | [Key] 15 | public TKey Id { get; set; } 16 | 17 | public DateTime CreatedOn { get; set; } 18 | 19 | public DateTime? ModifiedOn { get; set; } 20 | 21 | [Index] 22 | public bool IsDeleted { get; set; } 23 | 24 | public DateTime? DeletedOn { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Teams/TeamBattleViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Teams 7 | { 8 | using System; 9 | 10 | public class TeamBattleViewModel 11 | { 12 | public int Id { get; set; } 13 | 14 | public int OpponentTeamId { get; set; } 15 | 16 | public string OpponentTeam { get; set; } 17 | 18 | public bool IsFinished { get; set; } 19 | 20 | public int TeamWins { get; set; } 21 | 22 | public int OpponentWins { get; set; } 23 | 24 | public DateTime? ModifiedOn { get; set; } 25 | 26 | public string Comment { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/IDbRepository{T}.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Common 7 | { 8 | using System.Linq; 9 | 10 | using OnlineGames.Data.Common.Models; 11 | 12 | public interface IDbRepository : IDbRepository 13 | where T : BaseModel 14 | { 15 | } 16 | 17 | public interface IDbRepository 18 | where T : BaseModel 19 | { 20 | IQueryable All(); 21 | 22 | IQueryable AllWithDeleted(); 23 | 24 | T GetById(TKey id); 25 | 26 | void Add(T entity); 27 | 28 | void Delete(T entity); 29 | 30 | void HardDelete(T entity); 31 | 32 | void Save(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/UploadFileValidatorResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads 7 | { 8 | public class UploadFileValidatorResult 9 | { 10 | public UploadFileValidatorResult(string error) 11 | { 12 | this.IsValid = false; 13 | this.Error = error; 14 | } 15 | 16 | public UploadFileValidatorResult(byte[] fileContent) 17 | { 18 | this.IsValid = true; 19 | this.FileContent = fileContent; 20 | } 21 | 22 | public bool IsValid { get; } 23 | 24 | public string Error { get; } 25 | 26 | public byte[] FileContent { get; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Upload/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using OnlineGames.Web.AiPortal.Controllers 2 | @model OnlineGames.Web.AiPortal.ViewModels.Teams.TeamInfoViewModel 3 | @{ 4 | ViewBag.Title = $"Upload AI Library for {Model.Name}"; 5 | } 6 | 7 |

@ViewBag.Title

8 | 9 |
10 |
11 | 12 | 13 |

By uploading a new file with your AI all your results will be retested with the new version provided.

14 |

You will not be able to send another file for the next @UploadController.MinutesBetweenUploads minutes.

15 |
16 | 17 | @*Back to the team's page*@ 18 |
19 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201511282136457_Battles.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace OnlineGames.Data.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] 10 | public sealed partial class Battles : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(Battles)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201511282136457_Battles"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201511232031160_FileUploads.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace OnlineGames.Data.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] 10 | public sealed partial class FileUploads : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(FileUploads)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201511232031160_FileUploads"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Competitions/CompetitionViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Competitions 7 | { 8 | using System.Collections.Generic; 9 | 10 | using OnlineGames.Data.Models; 11 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 12 | using OnlineGames.Web.AiPortal.ViewModels.Teams; 13 | 14 | public class CompetitionViewModel : IMapFrom 15 | { 16 | public int Id { get; set; } 17 | 18 | public string Name { get; set; } 19 | 20 | public string Description { get; set; } 21 | 22 | public int MaximumParticipants { get; set; } 23 | 24 | public IEnumerable Teams { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Infrastructure/AiPortalPrincipal.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Infrastructure 7 | { 8 | using System.Collections.Generic; 9 | using System.Security.Principal; 10 | 11 | public class AiPortalPrincipal : IPrincipal 12 | { 13 | private readonly ICollection roles; 14 | 15 | public AiPortalPrincipal(string userName, ICollection roles) 16 | { 17 | this.roles = roles; 18 | this.Identity = new GenericIdentity(userName); 19 | } 20 | 21 | public IIdentity Identity { get; } 22 | 23 | public bool IsInRole(string role) 24 | { 25 | return this.roles.Contains(role); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201510221601215_InitialCreate.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace OnlineGames.Data.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.1.0-30225")] 10 | public sealed partial class InitialCreate : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(InitialCreate)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201510221601215_InitialCreate"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/User.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using System; 9 | using System.Collections.Generic; 10 | 11 | using OnlineGames.Data.Common.Models; 12 | 13 | public class User : BaseModel 14 | { 15 | public User() 16 | { 17 | this.Salt = Guid.NewGuid().ToString(); 18 | this.Roles = new HashSet(); 19 | } 20 | 21 | public string UserName { get; set; } 22 | 23 | public string AvatarUrl { get; set; } 24 | 25 | public string Salt { get; set; } 26 | 27 | public string PasswordHash { get; set; } 28 | 29 | public UserProvider Provider { get; set; } 30 | 31 | public virtual ICollection Roles { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Content/Site.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding-top: 50px; 3 | padding-bottom: 20px; 4 | } 5 | 6 | /* Set padding to keep content from hitting the edges */ 7 | .body-content { 8 | padding-left: 15px; 9 | padding-right: 15px; 10 | } 11 | 12 | /* Override the default bootstrap behavior where horizontal description lists 13 | will truncate terms that are too long to fit in the left column 14 | */ 15 | .dl-horizontal dt { 16 | white-space: normal; 17 | } 18 | 19 | /* Set width on the form input elements since they're 100% wide by default */ 20 | input, 21 | select, 22 | textarea { 23 | max-width: 280px; 24 | } 25 | 26 | hr { 27 | margin-top: 12px; 28 | margin-bottom: 12px; 29 | } 30 | 31 | /* Custom styles */ 32 | .points-cell { 33 | font-size: 20px; 34 | text-align: center; 35 | } 36 | 37 | .clip { 38 | -moz-text-overflow: ellpsis; 39 | text-overflow: ellipsis; 40 | } 41 | 42 | .overflow { 43 | width: 20em; 44 | white-space: nowrap; 45 | overflow: hidden; 46 | } 47 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201511291330516_GamesExecutorClassName.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | namespace OnlineGames.Data.Migrations 3 | { 4 | using System.CodeDom.Compiler; 5 | using System.Data.Entity.Migrations; 6 | using System.Data.Entity.Migrations.Infrastructure; 7 | using System.Resources; 8 | 9 | [GeneratedCode("EntityFramework.Migrations", "6.1.3-40302")] 10 | public sealed partial class GamesExecutorClassName : IMigrationMetadata 11 | { 12 | private readonly ResourceManager Resources = new ResourceManager(typeof(GamesExecutorClassName)); 13 | 14 | string IMigrationMetadata.Id 15 | { 16 | get { return "201511291330516_GamesExecutorClassName"; } 17 | } 18 | 19 | string IMigrationMetadata.Source 20 | { 21 | get { return null; } 22 | } 23 | 24 | string IMigrationMetadata.Target 25 | { 26 | get { return Resources.GetString("Target"); } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Uploads/All.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | @{ 3 | ViewBag.Title = "All uploads list"; 4 | } 5 | 6 |

@ViewBag.Title (Total: @Model.Count())

7 | @if (Model.Any()) 8 | { 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | @foreach (var upload in Model.OrderByDescending(x => x.CreatedOn)) 17 | { 18 | 19 | 20 | 21 | 22 | 23 | 24 | } 25 |
CompetitionTeam nameUploaded on
@upload.Id@upload.CompetitionName@upload.TeamName@upload.CreatedOn
26 | } 27 | else 28 | { 29 |

No uploads.

30 | } 31 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Teams/TeamInfoViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Teams 7 | { 8 | using System.Collections.Generic; 9 | 10 | using OnlineGames.Data.Models; 11 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 12 | 13 | public class TeamInfoViewModel : IMapFrom 14 | { 15 | public int Id { get; set; } 16 | 17 | public string Name { get; set; } 18 | 19 | public int Points { get; set; } 20 | 21 | public int UnfinishedBattles { get; set; } 22 | 23 | public IEnumerable TeamMembers { get; set; } 24 | 25 | public IEnumerable Uploads { get; set; } 26 | 27 | public IEnumerable Battles { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Teams/CreateTeamViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Teams 7 | { 8 | using System.Collections.Generic; 9 | using System.ComponentModel.DataAnnotations; 10 | 11 | public class CreateTeamViewModel 12 | { 13 | public CreateTeamViewModel() 14 | { 15 | this.TeamMembers = new List(); 16 | } 17 | 18 | [Display(Name = "Competition")] 19 | public int CompetitionId { get; set; } 20 | 21 | [Required] 22 | [StringLength(25, MinimumLength = 6)] 23 | [RegularExpression(@"[0-9a-zA-Z_\-.]+")] 24 | [Display(Name = "Team name")] 25 | public string Name { get; set; } 26 | 27 | public IList TeamMembers { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesSimulator/GamesSimulatorResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesSimulator 7 | { 8 | using System.Collections.Generic; 9 | 10 | public class GamesSimulatorResult 11 | { 12 | public GamesSimulatorResult(string comment) 13 | { 14 | this.BattleComment = comment; 15 | this.GameResults = new List(); 16 | } 17 | 18 | public GamesSimulatorResult(IEnumerable gameResults) 19 | { 20 | this.BattleComment = "Ready!"; 21 | this.GameResults = gameResults; 22 | } 23 | 24 | public string BattleComment { get; } 25 | 26 | public IEnumerable GameResults { get; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/Team.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using System.Collections.Generic; 9 | 10 | using OnlineGames.Data.Common.Models; 11 | 12 | public class Team : BaseModel 13 | { 14 | public Team() 15 | { 16 | this.TeamMembers = new HashSet(); 17 | this.Uploads = new HashSet(); 18 | } 19 | 20 | public string Name { get; set; } 21 | 22 | public int CompetitionId { get; set; } 23 | 24 | // TODO: Always update this cache value 25 | public int Points { get; set; } 26 | 27 | public virtual Competition Competition { get; set; } 28 | 29 | public virtual ICollection TeamMembers { get; set; } 30 | 31 | public virtual ICollection Uploads { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Teams/TeamMemberViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Teams 7 | { 8 | using AutoMapper; 9 | 10 | using OnlineGames.Data.Models; 11 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 12 | 13 | public class TeamMemberViewModel : IMapFrom, IHaveCustomMappings 14 | { 15 | public string UserName { get; set; } 16 | 17 | public string AvatarUrl { get; set; } 18 | 19 | public void CreateMappings(IConfiguration configuration) 20 | { 21 | configuration.CreateMap() 22 | .ForMember(x => x.UserName, opt => opt.MapFrom(x => x.User.UserName)) 23 | .ForMember(x => x.AvatarUrl, opt => opt.MapFrom(x => x.User.AvatarUrl)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNet.Identity 2 | @if (Request.IsAuthenticated) 3 | { 4 | using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" })) 5 | { 6 | @Html.AntiForgeryToken() 7 | 8 | 14 | } 15 | } 16 | else 17 | { 18 | 23 | } 24 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/Battle.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using System.Collections.Generic; 9 | using System.ComponentModel; 10 | 11 | using OnlineGames.Data.Common.Models; 12 | 13 | public class Battle : BaseModel 14 | { 15 | public Battle() 16 | { 17 | this.BattleGameResults = new HashSet(); 18 | } 19 | 20 | public int FirstTeamId { get; set; } 21 | 22 | public virtual Team FirstTeam { get; set; } 23 | 24 | public int SecondTeamId { get; set; } 25 | 26 | public virtual Team SecondTeam { get; set; } 27 | 28 | [DefaultValue(false)] 29 | public bool IsFinished { get; set; } 30 | 31 | public string Comment { get; set; } 32 | 33 | public virtual ICollection BattleGameResults { get; set; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Nikolay Kostov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/UploadsController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System.Linq; 9 | using System.Web.Mvc; 10 | 11 | using AutoMapper.QueryableExtensions; 12 | 13 | using OnlineGames.Data.Common; 14 | using OnlineGames.Data.Models; 15 | using OnlineGames.Web.AiPortal.ViewModels.Upload; 16 | 17 | public class UploadsController : Controller 18 | { 19 | private readonly IDbRepository uploadsRepository; 20 | 21 | public UploadsController(IDbRepository uploadsRepository) 22 | { 23 | this.uploadsRepository = uploadsRepository; 24 | } 25 | 26 | public ActionResult All() 27 | { 28 | var model = this.uploadsRepository.All().ProjectTo().ToList(); 29 | return this.View(model); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Infrastructure/AiPortalUserData.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Infrastructure 7 | { 8 | using System.Collections.Generic; 9 | 10 | public class AiPortalUserData 11 | { 12 | // ReSharper disable once UnusedMember.Global (required for JSON de-serializing) 13 | public AiPortalUserData() 14 | { 15 | } 16 | 17 | public AiPortalUserData(string userName, ICollection roles) 18 | { 19 | this.UserName = userName; 20 | this.Roles = roles; 21 | } 22 | 23 | public string UserName { get; set; } 24 | 25 | // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global (required for JSON de-serializing) 26 | // ReSharper disable once MemberCanBePrivate.Global (required for JSON de-serializing) 27 | public ICollection Roles { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Sandbox.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal 7 | { 8 | using System; 9 | using System.Security; 10 | using System.Security.Permissions; 11 | 12 | public static class Sandbox 13 | { 14 | public static AppDomain CreateSandbox() 15 | { 16 | var setup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase }; 17 | var permissionSet = new PermissionSet(PermissionState.None); 18 | permissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.NoFlags)); 19 | permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution)); 20 | permissionSet.AddPermission(new FileIOPermission(PermissionState.Unrestricted)); // TODO: !!! 21 | var appDomain = AppDomain.CreateDomain("Sandbox", null, setup, permissionSet); 22 | return appDomain; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Battles/Info.cshtml: -------------------------------------------------------------------------------- 1 | @using OnlineGames.Web.AiPortal.Infrastructure 2 | @model OnlineGames.Web.AiPortal.ViewModels.Battles.BattleInfoViewModel 3 | 4 | @{ 5 | ViewBag.Title = $"Battle №{Model.Id} - {Model.FirstTeamName} vs {Model.SecondTeamName}"; 6 | } 7 | 8 |

9 | @ViewBag.Title 10 | @if (User.IsAdmin()) 11 | { 12 | Restart 13 | } 14 |

15 |
16 |

@Model.Comment

17 |

Last modified on: @Model.ModifiedOn

18 |

Is finished: @Model.IsFinished

19 |
20 |

Games

21 | @if (Model.BattleGameResults.Any()) 22 | { 23 | 24 | 25 | 26 | 27 | 28 | 29 | @foreach (var game in Model.BattleGameResults.OrderBy(x => x.Id)) 30 | { 31 | 32 | 33 | 34 | 35 | 36 | } 37 |
IdWinnerInfo
@game.Id@game.BattleGameWinner@game.Report
38 | } 39 | else 40 | { 41 |

No games played.

42 | } 43 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/App_Start/BundleConfig.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal 7 | { 8 | using System.Web.Optimization; 9 | 10 | public static class BundleConfig 11 | { 12 | // For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 13 | public static void RegisterBundles(BundleCollection bundles) 14 | { 15 | bundles.Add(new ScriptBundle("~/bundles/jquery").Include( 16 | "~/Scripts/jquery-{version}.js")); 17 | 18 | bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( 19 | "~/Scripts/jquery.validate*")); 20 | 21 | bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( 22 | "~/Scripts/bootstrap.js")); 23 | 24 | bundles.Add(new StyleBundle("~/Content/css").Include( 25 | "~/Content/bootstrap.css", 26 | "~/Content/Darkly/bootstrap.css", 27 | "~/Content/site.css")); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Assets/AiPortal/Icons/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/Competition.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Models 7 | { 8 | using System.Collections.Generic; 9 | using System.ComponentModel; 10 | using System.ComponentModel.DataAnnotations; 11 | 12 | using OnlineGames.Data.Common.Models; 13 | 14 | public class Competition : BaseModel 15 | { 16 | public Competition() 17 | { 18 | this.Teams = new HashSet(); 19 | } 20 | 21 | [Required] 22 | public string Name { get; set; } 23 | 24 | public string Description { get; set; } 25 | 26 | public bool IsActive { get; set; } 27 | 28 | public int MinimumParticipants { get; set; } 29 | 30 | public int MaximumParticipants { get; set; } 31 | 32 | [DefaultValue(1000)] 33 | public int GamesToPlayForEachBattle { get; set; } 34 | 35 | public string LibraryValidatorClassName { get; set; } 36 | 37 | public string GamesExecutorClassName { get; set; } 38 | 39 | public virtual ICollection Teams { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Web.Debug.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/Program.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | [assembly: log4net.Config.XmlConfigurator(Watch = true)] 6 | 7 | namespace OnlineGames.Workers.BattlesSimulator 8 | { 9 | using System; 10 | using System.Diagnostics; 11 | using System.ServiceProcess; 12 | 13 | public static class Program 14 | { 15 | /// 16 | /// The main entry point for the application. 17 | /// 18 | public static void Main() 19 | { 20 | try 21 | { 22 | var servicesToRun = new ServiceBase[] { new BattlesSimulatorService() }; 23 | ServiceBase.Run(servicesToRun); 24 | } 25 | catch (Exception exception) 26 | { 27 | const string Source = "OnlineGames.Workers.BattlesSimulator"; 28 | if (!EventLog.SourceExists(Source)) 29 | { 30 | EventLog.CreateEventSource(Source, "Application"); 31 | } 32 | 33 | EventLog.WriteEntry(Source, exception.ToString(), EventLogEntryType.Error); 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Web.Release.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Upload/UploadInListViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Upload 7 | { 8 | using System; 9 | 10 | using AutoMapper; 11 | 12 | using OnlineGames.Data.Models; 13 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 14 | 15 | public class UploadInListViewModel : IMapFrom, IHaveCustomMappings 16 | { 17 | public int Id { get; set; } 18 | 19 | public DateTime CreatedOn { get; set; } 20 | 21 | public string CompetitionId { get; set; } 22 | 23 | public string CompetitionName { get; set; } 24 | 25 | public string TeamId { get; set; } 26 | 27 | public string TeamName { get; set; } 28 | 29 | public void CreateMappings(IConfiguration configuration) 30 | { 31 | configuration.CreateMap() 32 | .ForMember(x => x.TeamName, opt => opt.MapFrom(x => x.Team.Name)) 33 | .ForMember(x => x.CompetitionId, opt => opt.MapFrom(x => x.Team.CompetitionId)) 34 | .ForMember(x => x.CompetitionName, opt => opt.MapFrom(x => x.Team.Competition.Name)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Account/LoginWithTelerikAcademy.cshtml: -------------------------------------------------------------------------------- 1 | @model OnlineGames.Web.AiPortal.ViewModels.Account.ExternalLoginViewModel 2 | @{ 3 | ViewBag.Title = "Login with your telerikacademy.com account"; 4 | } 5 | 6 |

@ViewBag.Title

7 |
8 | 9 | @using (Html.BeginForm("LoginWithTelerikAcademy", "Account", new { ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 10 | { 11 | @Html.AntiForgeryToken() 12 | @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 13 |
14 | @Html.LabelFor(m => m.UserName, new { @class = "col-md-3 control-label" }) 15 |
16 | @Html.TextBoxFor(m => m.UserName, new { @class = "form-control" }) 17 | @Html.ValidationMessageFor(m => m.UserName, "", new { @class = "text-danger" }) 18 |
19 |
20 |
21 | @Html.LabelFor(m => m.Password, new { @class = "col-md-3 control-label" }) 22 |
23 | @Html.PasswordFor(m => m.Password, new { @class = "form-control" }) 24 | @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" }) 25 |
26 |
27 |
28 |
29 | 30 |
31 |
32 | } -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Battles/BattleInfoViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Battles 7 | { 8 | using System; 9 | using System.Collections.Generic; 10 | 11 | using AutoMapper; 12 | 13 | using OnlineGames.Data.Models; 14 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 15 | 16 | public class BattleInfoViewModel : IMapFrom, IHaveCustomMappings 17 | { 18 | public int Id { get; set; } 19 | 20 | public string FirstTeamName { get; set; } 21 | 22 | public string SecondTeamName { get; set; } 23 | 24 | public string Comment { get; set; } 25 | 26 | public bool IsFinished { get; set; } 27 | 28 | public DateTime? ModifiedOn { get; set; } 29 | 30 | public IEnumerable BattleGameResults { get; set; } 31 | 32 | public void CreateMappings(IConfiguration configuration) 33 | { 34 | configuration.CreateMap() 35 | .ForMember(m => m.FirstTeamName, opt => opt.MapFrom(b => b.FirstTeam.Name)) 36 | .ForMember(m => m.SecondTeamName, opt => opt.MapFrom(b => b.SecondTeam.Name)); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model OnlineGames.Web.AiPortal.ViewModels.Home.IndexViewModel 2 | @{ 3 | ViewBag.Title = "Home"; 4 | } 5 | 6 |
7 |
8 |
9 |

AI Competitions

10 |

Try your algoritmic skills.

11 |
12 |
13 | @if (!User.Identity.IsAuthenticated) 14 | { 15 | Login with telerikacademy.com » 16 | } 17 | else 18 | { 19 | foreach (var team in Model.CurrentUserTeams) 20 | { 21 | Team @team.Name »

22 | } 23 | 24 | Create a new team » 25 | } 26 |
27 |
28 |
29 |
30 |
31 | @foreach (var competition in Model.ActiveCompetitions) 32 | { 33 |
34 |

@competition.Name

35 | @Html.Raw(competition.Description) 36 |

37 | Check the rankings » 38 |

39 |
40 | } 41 |
42 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/BattlesSimulatorServiceInstaller.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator 7 | { 8 | using System.ComponentModel; 9 | using System.Configuration.Install; 10 | using System.ServiceProcess; 11 | 12 | [RunInstaller(true)] 13 | public class BattlesSimulatorServiceInstaller : Installer 14 | { 15 | public BattlesSimulatorServiceInstaller() 16 | { 17 | var serviceProcessInstaller = new ServiceProcessInstaller 18 | { 19 | Account = ServiceAccount.LocalSystem, 20 | Password = null, 21 | Username = null, 22 | }; 23 | 24 | var serviceInstaller = new ServiceInstaller 25 | { 26 | StartType = ServiceStartMode.Automatic, 27 | DisplayName = "AI Battles Simulator Service", 28 | ServiceName = "AI Battles Simulator Service", 29 | Description = 30 | "Simulates AI battles in GameAITesterOnline system. Battles are executed on the current machine.", 31 | }; 32 | 33 | this.Installers.AddRange(new Installer[] { serviceProcessInstaller, serviceInstaller }); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/SynchronizedHashtable.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator 7 | { 8 | using System; 9 | using System.Collections; 10 | 11 | public class SynchronizedHashtable 12 | { 13 | private readonly Hashtable hashtable; 14 | 15 | public SynchronizedHashtable() 16 | { 17 | var unsynchronizedHashtable = new Hashtable(); 18 | this.hashtable = Hashtable.Synchronized(unsynchronizedHashtable); 19 | } 20 | 21 | public bool Contains(object value) 22 | { 23 | return this.hashtable.ContainsKey(value); 24 | } 25 | 26 | public bool Add(object value) 27 | { 28 | if (this.hashtable.ContainsKey(value)) 29 | { 30 | return false; 31 | } 32 | 33 | try 34 | { 35 | this.hashtable.Add(value, true); 36 | return true; 37 | } 38 | catch (ArgumentException) 39 | { 40 | // The item is already in the hashtable. 41 | return false; 42 | } 43 | } 44 | 45 | public void Remove(object value) 46 | { 47 | this.hashtable.Remove(value); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/Settings.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator 7 | { 8 | using System; 9 | using System.Configuration; 10 | 11 | using log4net; 12 | 13 | public static class Settings 14 | { 15 | private static readonly ILog Logger; 16 | 17 | static Settings() 18 | { 19 | Logger = LogManager.GetLogger("Settings"); 20 | } 21 | 22 | public static int ThreadsCount => GetSettingOrDefault("ThreadsCount", 2); 23 | 24 | private static string GetSetting(string settingName) 25 | { 26 | if (ConfigurationManager.AppSettings[settingName] == null) 27 | { 28 | Logger.FatalFormat("{0} setting not found in App.config file!", settingName); 29 | throw new Exception($"{settingName} setting not found in App.config file!"); 30 | } 31 | 32 | return ConfigurationManager.AppSettings[settingName]; 33 | } 34 | 35 | private static T GetSettingOrDefault(string settingName, T defaultValue) 36 | { 37 | if (ConfigurationManager.AppSettings[settingName] == null) 38 | { 39 | return defaultValue; 40 | } 41 | 42 | return (T)Convert.ChangeType(ConfigurationManager.AppSettings[settingName], typeof(T)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Web.AiPortal")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Web.AiPortal")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("7313b10a-38be-465a-9096-393ee28367b3")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Revision and Build Numbers 37 | // by using the '*' as shown below: 38 | [assembly: AssemblyVersion("1.0.0.0")] 39 | [assembly: AssemblyFileVersion("1.0.0.0")] 40 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Data")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Data")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("e76453f3-4901-4294-a57f-cb2e78e04e05")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Source/OnlineGames.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Common")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Common")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("8e6474c8-d25f-41b1-a7de-4ac2f73c7d91")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Data.Common")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Data.Common")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("a4379059-f6ba-4e0d-b88d-b8e8c5d8eef1")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Models/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Data.Models")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Data.Models")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("fbdd7094-1c20-43d5-9882-252aededb7fa")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Services.AiPortal")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Services.AiPortal")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("d0d8006c-c1c3-47b0-8b41-9e2a3fbf7306")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using System.Reflection; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("OnlineGames.Workers.BattlesSimulator")] 13 | [assembly: AssemblyDescription("")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("")] 16 | [assembly: AssemblyProduct("OnlineGames.Workers.BattlesSimulator")] 17 | [assembly: AssemblyCopyright("Copyright © 2015")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // Setting ComVisible to false makes the types in this assembly not visible 22 | // to COM components. If you need to access a type in this assembly from 23 | // COM, set the ComVisible attribute to true on that type. 24 | [assembly: ComVisible(false)] 25 | 26 | // The following GUID is for the ID of the typelib if this project is exposed to COM 27 | [assembly: Guid("2d2ead39-bf24-4f57-8966-6e246e9a8ba6")] 28 | 29 | // Version information for an assembly consists of the following four values: 30 | // 31 | // Major Version 32 | // Minor Version 33 | // Build Number 34 | // Revision 35 | // 36 | // You can specify all the values or you can default the Build and Revision Numbers 37 | // by using the '*' as shown below: 38 | // [assembly: AssemblyVersion("1.0.*")] 39 | [assembly: AssemblyVersion("1.0.0.0")] 40 | [assembly: AssemblyFileVersion("1.0.0.0")] 41 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System.Linq; 9 | using System.Web.Mvc; 10 | 11 | using AutoMapper.QueryableExtensions; 12 | 13 | using OnlineGames.Data.Common; 14 | using OnlineGames.Data.Models; 15 | using OnlineGames.Web.AiPortal.ViewModels.Home; 16 | using OnlineGames.Web.AiPortal.ViewModels.Teams; 17 | 18 | public class HomeController : BaseController 19 | { 20 | private readonly IDbRepository competitionsRepository; 21 | 22 | private readonly IDbRepository teamsRepository; 23 | 24 | public HomeController(IDbRepository competitionsRepository, IDbRepository teamsRepository) 25 | { 26 | this.competitionsRepository = competitionsRepository; 27 | this.teamsRepository = teamsRepository; 28 | } 29 | 30 | public ActionResult Index() 31 | { 32 | var model = new IndexViewModel 33 | { 34 | ActiveCompetitions = 35 | this.competitionsRepository.All().Where(x => x.IsActive).ProjectTo(), 36 | CurrentUserTeams = 37 | this.teamsRepository.All() 38 | .Where(x => x.TeamMembers.Any(tm => tm.User.UserName == this.User.Identity.Name)) 39 | .ProjectTo(), 40 | }; 41 | return this.View(model); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Competitions/Info.cshtml: -------------------------------------------------------------------------------- 1 | @using OnlineGames.Web.AiPortal.Infrastructure 2 | @model OnlineGames.Web.AiPortal.ViewModels.Competitions.CompetitionViewModel 3 | @{ 4 | ViewBag.Title = Model.Name; 5 | var position = 0; 6 | } 7 | 8 |

9 | @ViewBag.Title (@Model.Teams.Count() teams) 10 | @if (User.IsAdmin()) 11 | { 12 | Create battles 13 | Restart battles 14 | } 15 |

16 |
17 | @Html.Raw(Model.Description) 18 | @foreach (var team in Model.Teams.OrderByDescending(x => x.Points).ThenBy(x => x.Id)) 19 | { 20 | position++; 21 |
22 |
23 |
24 |

25 | @position. 26 | @team.Name 27 | @if (team.Uploads.Any()) 28 | { 29 | 30 | } 31 | (@team.UnfinishedBattles) 32 |

33 |
34 | @foreach (var teammember in team.TeamMembers) 35 | { 36 |
37 | @teammember.UserName 38 | @teammember.UserName 39 |
40 | } 41 | @for (var i = team.TeamMembers.Count() + 1; i <= Model.MaximumParticipants; i++) 42 | { 43 |
44 | } 45 |
46 | @team.Points points 47 |
48 |
49 | } -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/ViewModels/Battles/BattleSimpleInfoViewModel.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.ViewModels.Battles 7 | { 8 | using System; 9 | using System.Linq; 10 | 11 | using AutoMapper; 12 | 13 | using OnlineGames.Data.Models; 14 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 15 | 16 | public class BattleSimpleInfoViewModel : IMapFrom, IHaveCustomMappings 17 | { 18 | public int Id { get; set; } 19 | 20 | public int FirstTeamId { get; set; } 21 | 22 | public string FirstTeamName { get; set; } 23 | 24 | public int FirstTeamWins { get; set; } 25 | 26 | public int SecondTeamId { get; set; } 27 | 28 | public string SecondTeamName { get; set; } 29 | 30 | public int SecondTeamWins { get; set; } 31 | 32 | public string Comment { get; set; } 33 | 34 | public bool IsFinished { get; set; } 35 | 36 | public DateTime? ModifiedOn { get; set; } 37 | 38 | public void CreateMappings(IConfiguration configuration) 39 | { 40 | configuration.CreateMap() 41 | .ForMember(m => m.FirstTeamName, opt => opt.MapFrom(b => b.FirstTeam.Name)) 42 | .ForMember(m => m.FirstTeamWins, opt => opt.MapFrom(b => b.BattleGameResults.Count(x => x.BattleGameWinner == BattleGameWinner.First))) 43 | .ForMember(m => m.SecondTeamName, opt => opt.MapFrom(b => b.SecondTeam.Name)) 44 | .ForMember(m => m.SecondTeamWins, opt => opt.MapFrom(b => b.BattleGameResults.Count(x => x.BattleGameWinner == BattleGameWinner.Second))); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201511232031160_FileUploads.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Migrations 7 | { 8 | using System.Data.Entity.Migrations; 9 | 10 | public partial class FileUploads : DbMigration 11 | { 12 | public override void Up() 13 | { 14 | this.CreateTable( 15 | "dbo.Uploads", 16 | c => 17 | new 18 | { 19 | Id = c.Int(nullable: false, identity: true), 20 | TeamId = c.Int(nullable: false), 21 | FileName = c.String(), 22 | FileContents = c.Binary(nullable: false), 23 | CreatedOn = c.DateTime(nullable: false), 24 | ModifiedOn = c.DateTime(), 25 | IsDeleted = c.Boolean(nullable: false), 26 | DeletedOn = c.DateTime(), 27 | }) 28 | .PrimaryKey(t => t.Id) 29 | .ForeignKey("dbo.Teams", t => t.TeamId, cascadeDelete: true) 30 | .Index(t => t.TeamId) 31 | .Index(t => t.IsDeleted); 32 | 33 | this.AddColumn("dbo.Competitions", "LibraryValidatorClassName", c => c.String()); 34 | } 35 | 36 | public override void Down() 37 | { 38 | this.DropForeignKey("dbo.Uploads", "TeamId", "dbo.Teams"); 39 | this.DropIndex("dbo.Uploads", new[] { "IsDeleted" }); 40 | this.DropIndex("dbo.Uploads", new[] { "TeamId" }); 41 | this.DropColumn("dbo.Competitions", "LibraryValidatorClassName"); 42 | this.DropTable("dbo.Uploads"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/RemoteDataService.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal 7 | { 8 | using System; 9 | using System.Net.Http; 10 | using System.Threading.Tasks; 11 | 12 | using Newtonsoft.Json; 13 | 14 | using OnlineGames.Services.AiPortal.Models; 15 | 16 | public class RemoteDataService : IRemoteDataService 17 | { 18 | // TODO: Pass as methods (or constructor) parameters 19 | private const string ApiKey = "3d33a038e0dbcaa7121c4f133dc474d7"; 20 | 21 | private const string BaseAddress = "https://telerikacademy.com"; 22 | 23 | private const string ApiCheckUserLoginUrlFormat = "/Api/Users/CheckUserLogin?apiKey={0}&usernameoremail={1}&password={2}"; 24 | 25 | private readonly HttpClient client; 26 | 27 | public RemoteDataService() 28 | { 29 | this.client = new HttpClient { BaseAddress = new Uri(BaseAddress) }; 30 | this.client.DefaultRequestHeaders.Add("Connection", "close"); 31 | } 32 | 33 | public async Task Login(string username, string password) 34 | { 35 | var url = string.Format(ApiCheckUserLoginUrlFormat, ApiKey, username, password); 36 | var remoteUser = await this.RemoteGet(url); 37 | return remoteUser; 38 | } 39 | 40 | private async Task RemoteGet(string url) 41 | { 42 | var response = await this.client.GetAsync(url); 43 | var jsonString = await response.Content.ReadAsStringAsync(); 44 | var model = JsonConvert.DeserializeObject(jsonString); 45 | return model; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/DbRepository{T}.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Common 7 | { 8 | using System; 9 | using System.Data.Entity; 10 | using System.Linq; 11 | 12 | using OnlineGames.Data.Common.Models; 13 | 14 | public class DbRepository : IDbRepository 15 | where T : BaseModel 16 | { 17 | public DbRepository(DbContext context) 18 | { 19 | if (context == null) 20 | { 21 | throw new ArgumentException("An instance of DbContext is required to use this repository.", nameof(context)); 22 | } 23 | 24 | this.Context = context; 25 | this.DbSet = this.Context.Set(); 26 | } 27 | 28 | private IDbSet DbSet { get; } 29 | 30 | private DbContext Context { get; } 31 | 32 | public IQueryable All() 33 | { 34 | return this.DbSet.Where(x => !x.IsDeleted); 35 | } 36 | 37 | public IQueryable AllWithDeleted() 38 | { 39 | return this.DbSet; 40 | } 41 | 42 | public T GetById(int id) 43 | { 44 | return this.All().FirstOrDefault(x => x.Id == id); 45 | } 46 | 47 | public void Add(T entity) 48 | { 49 | this.DbSet.Add(entity); 50 | } 51 | 52 | public void Delete(T entity) 53 | { 54 | entity.IsDeleted = true; 55 | entity.DeletedOn = DateTime.Now; 56 | } 57 | 58 | public void HardDelete(T entity) 59 | { 60 | this.DbSet.Remove(entity); 61 | } 62 | 63 | public void Save() 64 | { 65 | this.Context.SaveChanges(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/BattlesController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System.Linq; 9 | using System.Web.Mvc; 10 | 11 | using AutoMapper.QueryableExtensions; 12 | 13 | using OnlineGames.Common; 14 | using OnlineGames.Data.Common; 15 | using OnlineGames.Data.Models; 16 | using OnlineGames.Web.AiPortal.ViewModels.Battles; 17 | 18 | public class BattlesController : Controller 19 | { 20 | private readonly IDbRepository battlesRepository; 21 | 22 | public BattlesController(IDbRepository battlesRepository) 23 | { 24 | this.battlesRepository = battlesRepository; 25 | } 26 | 27 | public ActionResult Info(int id) 28 | { 29 | var model = this.battlesRepository.All().Where(x => x.Id == id).ProjectTo().FirstOrDefault(); 30 | if (model == null) 31 | { 32 | return this.HttpNotFound("Battle not found!"); 33 | } 34 | 35 | return this.View(model); 36 | } 37 | 38 | [Authorize(Roles = GlobalConstants.AdministratorRoleName)] 39 | public ActionResult Restart(int id) 40 | { 41 | var battle = this.battlesRepository.GetById(id); 42 | battle.IsFinished = false; 43 | this.battlesRepository.Save(); 44 | this.TempData["Info"] = "Battle restarted."; 45 | return this.RedirectToAction(nameof(this.Info), new { id }); 46 | } 47 | 48 | public ActionResult All() 49 | { 50 | var model = this.battlesRepository.All().ProjectTo().ToList(); 51 | return this.View(model); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Properties/PublishProfiles/78.128.6.6.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | MSDeploy 9 | False 10 | Release 11 | Any CPU 12 | http://ai.bgcoder.com 13 | True 14 | False 15 | http://78.128.6.6 16 | ai.bgcoder.com 17 | 18 | True 19 | RemoteAgent 20 | True 21 | Administrator 22 | <_SavePWD>False 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Properties/PublishProfiles/TelerikAcademyServer.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | MSDeploy 9 | Release 10 | Any CPU 11 | http://ai.bgcoder.com 12 | True 13 | False 14 | https://79.124.44.83:8172/MsDeploy.axd 15 | ai.bgcoder.com 16 | 17 | True 18 | WMSVC 19 | True 20 | acadwebadmin 21 | <_SavePWD>False 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | False 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/AiPortalDbContext.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data 7 | { 8 | using System; 9 | using System.Data.Entity; 10 | using System.Linq; 11 | 12 | using OnlineGames.Data.Common.Models; 13 | using OnlineGames.Data.Models; 14 | 15 | public class AiPortalDbContext : DbContext 16 | { 17 | public AiPortalDbContext() 18 | : base("DefaultConnection") 19 | { 20 | } 21 | 22 | public DbSet Users { get; set; } 23 | 24 | public DbSet Roles { get; set; } 25 | 26 | public DbSet Competitions { get; set; } 27 | 28 | public DbSet Teams { get; set; } 29 | 30 | public DbSet Uploads { get; set; } 31 | 32 | public DbSet Battles { get; set; } 33 | 34 | public DbSet BattleGameResults { get; set; } 35 | 36 | public override int SaveChanges() 37 | { 38 | this.ApplyAuditInfoRules(); 39 | return base.SaveChanges(); 40 | } 41 | 42 | private void ApplyAuditInfoRules() 43 | { 44 | // Approach via @julielerman: http://bit.ly/123661P 45 | foreach (var entry in 46 | this.ChangeTracker.Entries() 47 | .Where( 48 | e => 49 | e.Entity is IAuditInfo && ((e.State == EntityState.Added) || (e.State == EntityState.Modified)))) 50 | { 51 | var entity = (IAuditInfo)entry.Entity; 52 | if (entry.State == EntityState.Added && entity.CreatedOn == default(DateTime)) 53 | { 54 | entity.CreatedOn = DateTime.Now; 55 | } 56 | else 57 | { 58 | entity.ModifiedOn = DateTime.Now; 59 | } 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/BaseGamesExecutor.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Reflection; 12 | 13 | using OnlineGames.Workers.BattlesSimulator.GamesSimulator; 14 | 15 | public abstract class BaseGamesExecutor : IGamesExecutor 16 | { 17 | public abstract IEnumerable SimulateGames(Assembly firstAssembly, Assembly secondAssembly, int count); 18 | 19 | protected T LoadPlayer(Assembly assembly) 20 | where T : class 21 | { 22 | var playerClasses = 23 | assembly.GetTypes() 24 | .Where(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(T).IsAssignableFrom(x)).ToList(); 25 | if (playerClasses.Count > 1) 26 | { 27 | throw new GameSimulationException($"More than one public inheritant of IPlayer found in {assembly.FullName}"); 28 | } 29 | 30 | if (playerClasses.Count == 0) 31 | { 32 | throw new GameSimulationException($"No public types that inherit IPlayer (or BasePlayer) found in {assembly.FullName}"); 33 | } 34 | 35 | var playerClass = playerClasses[0]; 36 | 37 | // TODO: Time limit (if available use decorator from the library) 38 | // TODO: var sandbox = Sandbox.CreateSandbox(); 39 | // TODO: firstInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer; 40 | // TODO: secondInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer; 41 | var instance = Activator.CreateInstance(playerClass) as T; 42 | return instance; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Global.asax.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal 7 | { 8 | using System; 9 | using System.Data.Entity; 10 | using System.Web; 11 | using System.Web.Mvc; 12 | using System.Web.Optimization; 13 | using System.Web.Routing; 14 | using System.Web.Script.Serialization; 15 | using System.Web.Security; 16 | 17 | using OnlineGames.Data; 18 | using OnlineGames.Data.Migrations; 19 | using OnlineGames.Web.AiPortal.Infrastructure; 20 | using OnlineGames.Web.AiPortal.Infrastructure.Mapping; 21 | 22 | [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name must match first type name", Justification = "File name must be Global.asax.cs")] 23 | public class MvcApplication : HttpApplication 24 | { 25 | protected void Application_Start() 26 | { 27 | Database.SetInitializer(new MigrateDatabaseToLatestVersion()); 28 | 29 | AreaRegistration.RegisterAllAreas(); 30 | FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); 31 | RouteConfig.RegisterRoutes(RouteTable.Routes); 32 | BundleConfig.RegisterBundles(BundleTable.Bundles); 33 | 34 | var autoMapperConfig = new AutoMapperConfig(); 35 | autoMapperConfig.Execute(); 36 | } 37 | 38 | protected void Application_PostAuthenticateRequest(object sender, EventArgs e) 39 | { 40 | var authCookie = this.Request.Cookies[FormsAuthentication.FormsCookieName]; 41 | if (authCookie != null) 42 | { 43 | var authTicket = FormsAuthentication.Decrypt(authCookie.Value); 44 | var serializer = new JavaScriptSerializer(); 45 | var userData = serializer.Deserialize(authTicket.UserData); 46 | HttpContext.Current.User = new AiPortalPrincipal(userData.UserName, userData.Roles); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Infrastructure/Mapping/AutoMapperConfig.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Infrastructure.Mapping 7 | { 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Reflection; 12 | using AutoMapper; 13 | 14 | public class AutoMapperConfig 15 | { 16 | public void Execute() 17 | { 18 | var types = Assembly.GetExecutingAssembly().GetExportedTypes(); 19 | 20 | LoadStandardMappings(types); 21 | 22 | LoadCustomMappings(types); 23 | } 24 | 25 | private static void LoadStandardMappings(IEnumerable types) 26 | { 27 | var maps = (from t in types 28 | from i in t.GetInterfaces() 29 | where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>) && 30 | !t.IsAbstract && 31 | !t.IsInterface 32 | select new 33 | { 34 | Source = i.GetGenericArguments()[0], 35 | Destination = t, 36 | }).ToArray(); 37 | 38 | foreach (var map in maps) 39 | { 40 | Mapper.CreateMap(map.Source, map.Destination); 41 | } 42 | } 43 | 44 | private static void LoadCustomMappings(IEnumerable types) 45 | { 46 | var maps = (from t in types 47 | from i in t.GetInterfaces() 48 | where typeof(IHaveCustomMappings).IsAssignableFrom(t) && 49 | !t.IsAbstract && 50 | !t.IsInterface 51 | select (IHaveCustomMappings)Activator.CreateInstance(t)).ToArray(); 52 | 53 | foreach (var map in maps) 54 | { 55 | map.CreateMappings(Mapper.Configuration); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/SantaseGamesExecutor.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using System.Collections.Generic; 9 | using System.Diagnostics; 10 | using System.Reflection; 11 | 12 | using OnlineGames.Data.Models; 13 | using OnlineGames.Workers.BattlesSimulator.GamesSimulator; 14 | 15 | using Santase.Logic; 16 | using Santase.Logic.GameMechanics; 17 | using Santase.Logic.Players; 18 | 19 | public class SantaseGamesExecutor : BaseGamesExecutor 20 | { 21 | public override IEnumerable SimulateGames(Assembly firstAssembly, Assembly secondAssembly, int count) 22 | { 23 | // TODO: Decorate with time and memory limit 24 | // TODO: What if someone crashes? 25 | var firstPlayer = this.LoadPlayer(firstAssembly); 26 | var secondPlayer = this.LoadPlayer(secondAssembly); 27 | 28 | var gameResults = new List(); 29 | for (var i = 0; i < count; i++) 30 | { 31 | var game = new SantaseGame(firstPlayer, secondPlayer); 32 | var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer; 33 | 34 | var stopwatch = Stopwatch.StartNew(); 35 | var gameWinner = game.Start(firstToPlay); 36 | var elapsed = stopwatch.Elapsed; 37 | 38 | var report = $"First: {firstToPlay}; Result: {game.FirstPlayerTotalPoints} - {game.SecondPlayerTotalPoints} (in {game.RoundsPlayed} rounds) Time: {elapsed}"; 39 | var gameResult = 40 | new SingleGameResult( 41 | gameWinner == PlayerPosition.FirstPlayer ? BattleGameWinner.First : BattleGameWinner.Second, 42 | report); 43 | 44 | gameResults.Add(gameResult); 45 | } 46 | 47 | return gameResults; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Battles/All.cshtml: -------------------------------------------------------------------------------- 1 | @model IEnumerable 2 | 3 | @{ 4 | ViewBag.Title = "All battles list"; 5 | } 6 | 7 |

@ViewBag.Title (Total: @Model.Count(); Unfinished: @Model.Count(x => !x.IsFinished))

8 | @if (Model.Any()) 9 | { 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @foreach (var battle in Model.OrderByDescending(x => x.ModifiedOn).ThenBy(x => x.FirstTeamName).ThenBy(x => x.SecondTeamName)) 22 | { 23 | var rowClass = ""; 24 | var tdClassIsFinished = ""; 25 | if (!battle.IsFinished) 26 | { 27 | rowClass = "active"; 28 | tdClassIsFinished = "glyphicon glyphicon-remove text-danger"; 29 | } 30 | else 31 | { 32 | tdClassIsFinished = "glyphicon glyphicon-ok text-success"; 33 | } 34 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 46 | 47 | } 48 |
First teamResultSecond teamCommentReadyLast change
@battle.Id@battle.FirstTeamName@battle.FirstTeamWins - @battle.SecondTeamWins@battle.SecondTeamName 40 | 41 |

@battle.Comment

42 |
43 |
@battle.ModifiedOn
49 |
50 | } 51 | else 52 | { 53 |

No battles.

54 | } 55 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | @ViewBag.Title - AI Competitions 8 | @Styles.Render("~/Content/css") 9 | 10 | 11 | 32 |
33 | @if (!string.IsNullOrWhiteSpace(ViewBag.Error)) 34 | { 35 |
@ViewBag.Error
36 | } 37 | @if (TempData["Error"] != null) 38 | { 39 |
@TempData["Error"]
40 | } 41 | @if (!string.IsNullOrWhiteSpace(ViewBag.Info)) 42 | { 43 |
@ViewBag.Info
44 | } 45 | @if (TempData["Info"] != null) 46 | { 47 |
@TempData["Info"]
48 | } 49 | @RenderBody() 50 |
51 | 54 |
55 | 56 | @Scripts.Render("~/bundles/jquery") 57 | @Scripts.Render("~/bundles/bootstrap") 58 | @RenderSection("scripts", required: false) 59 | 60 | 61 | -------------------------------------------------------------------------------- /Source/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | True 6 | 7 | 8 | 9 | 10 | 2000 11 | 12 | Json 13 | xaml 14 | ciphertext 15 | Rijndael 16 | unenroll 17 | unenrollment 18 | bgcoder 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | False 27 | 28 | 29 | 30 | 31 | False 32 | 33 | 34 | 35 | 36 | False 37 | 38 | 39 | 40 | 41 | False 42 | 43 | 44 | 45 | 46 | False 47 | 48 | 49 | 50 | 51 | True 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | at 61 | db 62 | or 63 | up 64 | iq 65 | it 66 | un 67 | bg 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesSimulator/GamesSimulator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesSimulator 7 | { 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Reflection; 11 | 12 | using OnlineGames.Workers.BattlesSimulator.GamesExecutors; 13 | 14 | public class GamesSimulator : IGamesSimulator 15 | { 16 | public GamesSimulatorResult SimulateGames(byte[] firstAssemblyAsBytes, byte[] secondAssemblyAsBytes, string gamesExecutorClassName) 17 | { 18 | // Create assemblies 19 | Assembly firstAssembly; 20 | Assembly secondAssembly; 21 | try 22 | { 23 | firstAssembly = Assembly.Load(firstAssemblyAsBytes); 24 | secondAssembly = Assembly.Load(secondAssemblyAsBytes); 25 | } 26 | catch (Exception ex) 27 | { 28 | return new GamesSimulatorResult($"Could not load one or more of the assemblies: {ex}"); 29 | } 30 | 31 | IGamesExecutor gamesExecutor; 32 | try 33 | { 34 | gamesExecutor = this.CreateGamesExecutor(gamesExecutorClassName); 35 | } 36 | catch (Exception ex) 37 | { 38 | return new GamesSimulatorResult($"Could not load the games executor class: {ex}"); 39 | } 40 | 41 | IEnumerable gameResults; 42 | try 43 | { 44 | gameResults = gamesExecutor.SimulateGames(firstAssembly, secondAssembly, 1000); 45 | } 46 | catch (Exception ex) 47 | { 48 | return new GamesSimulatorResult($"Uncaught exception during game simulations: {ex}"); 49 | } 50 | 51 | return new GamesSimulatorResult(gameResults); 52 | } 53 | 54 | private IGamesExecutor CreateGamesExecutor(string fullClassName) 55 | { 56 | var libraryValidator = fullClassName != null 57 | ? Activator.CreateInstance( 58 | typeof(IGamesExecutor).Assembly.FullName, 59 | fullClassName).Unwrap() as IGamesExecutor 60 | : null; 61 | return libraryValidator; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/BattlesSimulatorService.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator 7 | { 8 | using System.Collections.Generic; 9 | using System.ServiceProcess; 10 | using System.Threading; 11 | 12 | using log4net; 13 | 14 | public class BattlesSimulatorService : ServiceBase 15 | { 16 | private static ILog logger; 17 | private readonly IList threads; 18 | private readonly IList jobs; 19 | 20 | public BattlesSimulatorService() 21 | { 22 | logger = LogManager.GetLogger("BattlesSimulatorService"); 23 | logger.Info("BattlesSimulatorService initializing..."); 24 | 25 | this.threads = new List(); 26 | this.jobs = new List(); 27 | 28 | // Shared among jobs 29 | var processingBattleIds = new SynchronizedHashtable(); 30 | 31 | for (int i = 1; i <= Settings.ThreadsCount; i++) 32 | { 33 | IJob job = new BattlesSimulatorJob($"Job №{i}", processingBattleIds); 34 | var thread = new Thread(job.Start) { Name = $"Thread №{i}" }; 35 | this.jobs.Add(job); 36 | this.threads.Add(thread); 37 | } 38 | 39 | logger.Info("BattlesSimulatorService initialized."); 40 | } 41 | 42 | protected override void OnStart(string[] args) 43 | { 44 | logger.Info("BattlesSimulatorService starting..."); 45 | 46 | foreach (var thread in this.threads) 47 | { 48 | logger.InfoFormat("Starting {0}...", thread.Name); 49 | thread.Start(); 50 | logger.InfoFormat("{0} started.", thread.Name); 51 | Thread.Sleep(234); 52 | } 53 | 54 | logger.Info("BattlesSimulatorService started."); 55 | } 56 | 57 | protected override void OnStop() 58 | { 59 | logger.Info("BattlesSimulatorService stopping..."); 60 | 61 | foreach (var job in this.jobs) 62 | { 63 | job.Stop(); 64 | logger.InfoFormat("{0} stopped.", job.Name); 65 | } 66 | 67 | Thread.Sleep(10000); 68 | 69 | foreach (var thread in this.threads) 70 | { 71 | thread.Abort(); 72 | logger.InfoFormat("{0} aborted.", thread.Name); 73 | } 74 | 75 | logger.Info("BattlesSimulatorService stopped."); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/TexasHoldemGamesExecutor.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using System.Collections.Generic; 9 | using System.Diagnostics; 10 | using System.Reflection; 11 | 12 | using OnlineGames.Data.Models; 13 | using OnlineGames.Workers.BattlesSimulator.GamesSimulator; 14 | 15 | using TexasHoldem.Logic.GameMechanics; 16 | using TexasHoldem.Logic.Players; 17 | 18 | public class TexasHoldemGamesExecutor : BaseGamesExecutor 19 | { 20 | public override IEnumerable SimulateGames(Assembly firstAssembly, Assembly secondAssembly, int count) 21 | { 22 | count = 100; 23 | var firstPlayer = new TexasHoldemPlayerDirector(this.LoadPlayer(firstAssembly)); 24 | var secondPlayer = new TexasHoldemPlayerDirector(this.LoadPlayer(secondAssembly)); 25 | 26 | var gameResults = new List(); 27 | for (var i = 0; i < count; i++) 28 | { 29 | var game = i % 2 == 0 30 | ? new TwoPlayersTexasHoldemGame(firstPlayer, secondPlayer) 31 | : new TwoPlayersTexasHoldemGame(secondPlayer, firstPlayer); 32 | 33 | var stopwatch = Stopwatch.StartNew(); 34 | var winner = game.Start(); 35 | var elapsed = stopwatch.Elapsed; 36 | 37 | var firstToPlay = i % 2 == 0 ? "FirstPlayer" : "SecondPlayer"; 38 | var winnerAsString = winner.Name == firstPlayer.Name ? "FirstPlayer" : "SecondPlayer"; 39 | var report = $"First: {firstToPlay}; Winner: {winnerAsString} ({game.HandsPlayed} hands); Time: {elapsed}; Crashes: {firstPlayer.Crashes} - {secondPlayer.Crashes}; Time limits: {firstPlayer.TimeOuts} - {secondPlayer.TimeOuts}"; 40 | if (firstPlayer.FirstCrash != null) 41 | { 42 | report += $"; First player first exception: {firstPlayer.FirstCrash}"; 43 | } 44 | 45 | if (secondPlayer.FirstCrash != null) 46 | { 47 | report += $"; Second player first exception: {secondPlayer.FirstCrash}"; 48 | } 49 | 50 | var gameResult = 51 | new SingleGameResult( 52 | winner.Name == firstPlayer.Name ? BattleGameWinner.First : BattleGameWinner.Second, 53 | report); 54 | 55 | gameResults.Add(gameResult); 56 | } 57 | 58 | return gameResults; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Battles/BattlesGenerator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Battles 7 | { 8 | using System.Linq; 9 | 10 | using OnlineGames.Data.Common; 11 | using OnlineGames.Data.Models; 12 | 13 | public class BattlesGenerator : IBattlesGenerator 14 | { 15 | public int GenerateBattles(IDbRepository teamsRepository, IDbRepository battlesRepository, int competitionId) 16 | { 17 | var teams = teamsRepository.All().Where(x => x.CompetitionId == competitionId).Select(x => new { x.Id }).ToList(); 18 | var newBattles = 0; 19 | for (var i = 0; i < teams.Count; i++) 20 | { 21 | for (int j = i + 1; j < teams.Count; j++) 22 | { 23 | var firstTeam = teams[i]; 24 | var secondTeam = teams[j]; 25 | if (battlesRepository.All().Any( 26 | x => 27 | (x.FirstTeamId == firstTeam.Id && x.SecondTeamId == secondTeam.Id) 28 | || (x.FirstTeamId == secondTeam.Id && x.FirstTeamId == firstTeam.Id))) 29 | { 30 | // Battle already exists 31 | continue; 32 | } 33 | 34 | newBattles++; 35 | battlesRepository.Add(new Battle { FirstTeamId = firstTeam.Id, SecondTeamId = secondTeam.Id }); 36 | } 37 | } 38 | 39 | battlesRepository.Save(); 40 | return newBattles; 41 | } 42 | 43 | public int RestartBattlesForCompetition(IDbRepository battlesRepository, int competitionId) 44 | { 45 | var battlesForRestarting = 46 | battlesRepository.All() 47 | .Where( 48 | x => x.FirstTeam.CompetitionId == competitionId || x.SecondTeam.CompetitionId == competitionId) 49 | .ToList(); 50 | foreach (var battle in battlesForRestarting) 51 | { 52 | battle.IsFinished = false; 53 | } 54 | 55 | battlesRepository.Save(); 56 | return battlesForRestarting.Count; 57 | } 58 | 59 | public void RestartBattlesForTeam(IDbRepository battlesRepository, int teamId) 60 | { 61 | var battlesForTeam = battlesRepository.All().Where(x => x.FirstTeamId == teamId || x.SecondTeamId == teamId); 62 | foreach (var battle in battlesForTeam) 63 | { 64 | battle.IsFinished = false; 65 | } 66 | 67 | battlesRepository.Save(); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/UploadFileValidator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads 7 | { 8 | using System; 9 | using System.IO; 10 | using System.Reflection; 11 | 12 | using OnlineGames.Services.AiPortal.Uploads.LibraryValidators; 13 | 14 | public class UploadFileValidator : IUploadFileValidator 15 | { 16 | public UploadFileValidatorResult ValidateFile( 17 | string fileName, 18 | int contentLength, 19 | Stream inputStream, 20 | ILibraryValidator libraryValidator) 21 | { 22 | if (!fileName.EndsWith(".dll")) 23 | { 24 | return new UploadFileValidatorResult("Only .dll files are supported."); 25 | } 26 | 27 | if ((contentLength / 1024) / 1024 > 2) 28 | { 29 | return new UploadFileValidatorResult("Files should be less than 2MB."); 30 | } 31 | 32 | byte[] fileData; 33 | try 34 | { 35 | using (var binaryReader = new BinaryReader(inputStream)) 36 | { 37 | fileData = binaryReader.ReadBytes(contentLength); 38 | } 39 | } 40 | catch (Exception ex) 41 | { 42 | return new UploadFileValidatorResult($"File reading error: {ex.Message}"); 43 | } 44 | 45 | Assembly assembly; 46 | try 47 | { 48 | assembly = Assembly.Load(fileData); 49 | } 50 | catch (Exception ex) 51 | { 52 | return new UploadFileValidatorResult($"Loading assembly failed: {ex.Message}"); 53 | } 54 | 55 | if (libraryValidator != null) 56 | { 57 | var libraryValidatorResult = libraryValidator.Validate(assembly); 58 | if (!libraryValidatorResult.IsValid) 59 | { 60 | return new UploadFileValidatorResult($"Library validation failed: {libraryValidatorResult.Error}"); 61 | } 62 | } 63 | 64 | return new UploadFileValidatorResult(fileData); 65 | } 66 | 67 | public ILibraryValidator CreateLibraryValidator(string fullClassName) 68 | { 69 | var libraryValidator = fullClassName != null 70 | ? Activator.CreateInstance( 71 | typeof(ILibraryValidator).Assembly.FullName, 72 | fullClassName).Unwrap() as ILibraryValidator 73 | : null; 74 | return libraryValidator; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Teams/Create.cshtml: -------------------------------------------------------------------------------- 1 | @model OnlineGames.Web.AiPortal.ViewModels.Teams.CreateTeamViewModel 2 | @{ 3 | ViewBag.Title = "Create a new team"; 4 | } 5 | 6 |

@ViewBag.Title

7 |
8 |
9 | Step One: All team members should login in this system and have valid accounts.
10 | Step Two: One of the team members should create the team on this page (no matter who) by selecting one of the competitions from the drop down menu and selecting team name (which cannot be changed later). The name of the team should be between 6 and 25 symbols. Allowed symbols: latting letters, numbers, dot and underscore.
11 | Step Three: The one who creates the team should specify the usernames of all teammates in this form 12 |
13 | @using (Html.BeginForm("Create", "Teams", FormMethod.Post, new { @class = "form-horizontal", role = "form" })) 14 | { 15 | @Html.AntiForgeryToken() 16 | @Html.ValidationSummary(true, "", new { @class = "text-danger" }) 17 |
18 | @Html.LabelFor(m => m.CompetitionId, new { @class = "col-md-3 control-label" }) 19 |
20 | @Html.DropDownListFor(m => m.CompetitionId, ViewBag.Competitions as IEnumerable, new { @class = "form-control" }) 21 | @Html.ValidationMessageFor(m => m.CompetitionId, "", new { @class = "text-danger" }) 22 |
23 |
24 |
25 | @Html.LabelFor(m => m.Name, new { @class = "col-md-3 control-label" }) 26 |
27 | @Html.TextBoxFor(m => m.Name, new { @class = "form-control" }) 28 | @Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" }) 29 |
30 |
31 |
32 | 33 |
34 | 35 | 36 |
37 |
38 | for (var i = 1; i < ViewBag.MaxTeamMembers; i++) 39 | { 40 | var value = string.Empty; 41 | if (Model.TeamMembers.Count >= i) 42 | { 43 | value = Model.TeamMembers[i]; 44 | } 45 |
46 | 47 |
48 | 49 |
50 |
51 | } 52 |
53 |
54 | 55 |
56 |
57 | } 58 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/LibraryValidators/TexasHoldemLibraryValidator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads.LibraryValidators 7 | { 8 | using System; 9 | using System.Linq; 10 | using System.Reflection; 11 | 12 | using TexasHoldem.Logic.GameMechanics; 13 | using TexasHoldem.Logic.Players; 14 | 15 | public class TexasHoldemLibraryValidator : ILibraryValidator 16 | { 17 | public LibraryValidatorResult Validate(Assembly assembly) 18 | { 19 | var playerClasses = 20 | assembly.GetTypes() 21 | .Where(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(IPlayer).IsAssignableFrom(x)).ToList(); 22 | if (playerClasses.Count > 1) 23 | { 24 | return new LibraryValidatorResult("More than one public inheritant of IPlayer found."); 25 | } 26 | 27 | if (playerClasses.Count == 0) 28 | { 29 | return new LibraryValidatorResult("No public types that inherit IPlayer (or BasePlayer) found!"); 30 | } 31 | 32 | var playerClass = playerClasses[0]; 33 | IPlayer firstInstance; 34 | IPlayer secondInstance; 35 | try 36 | { 37 | // TODO: var sandbox = Sandbox.CreateSandbox(); 38 | // TODO: firstInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer; 39 | // TODO: secondInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer; 40 | firstInstance = Activator.CreateInstance(playerClass) as IPlayer; 41 | secondInstance = Activator.CreateInstance(playerClass) as IPlayer; 42 | } 43 | catch (Exception ex) 44 | { 45 | return new LibraryValidatorResult($"Creating instance of \"{playerClass.Name}\" failed: {ex.Message}"); 46 | } 47 | 48 | if (firstInstance == null || secondInstance == null) 49 | { 50 | return new LibraryValidatorResult($"Instance of \"{playerClass.Name}\" is null."); 51 | } 52 | 53 | try 54 | { 55 | var santaseGame = new TwoPlayersTexasHoldemGame(firstInstance, secondInstance); 56 | santaseGame.Start(); 57 | santaseGame = new TwoPlayersTexasHoldemGame(secondInstance, firstInstance); 58 | santaseGame.Start(); 59 | } 60 | catch (Exception ex) 61 | { 62 | return new LibraryValidatorResult($"Playing a new game between two instances of your player failed: {ex.Message}"); 63 | } 64 | 65 | return new LibraryValidatorResult(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/App_Start/NinjectWebCommon.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | using OnlineGames.Web.AiPortal; 7 | 8 | [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(NinjectWebCommon), "Start")] 9 | [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(NinjectWebCommon), "Stop")] 10 | 11 | namespace OnlineGames.Web.AiPortal 12 | { 13 | using System; 14 | using System.Data.Entity; 15 | using System.Web; 16 | 17 | using Microsoft.Web.Infrastructure.DynamicModuleHelper; 18 | 19 | using Ninject; 20 | using Ninject.Web.Common; 21 | 22 | using OnlineGames.Data; 23 | using OnlineGames.Data.Common; 24 | using OnlineGames.Services.AiPortal.Battles; 25 | using OnlineGames.Services.AiPortal.Uploads; 26 | 27 | public static class NinjectWebCommon 28 | { 29 | private static readonly Bootstrapper Bootstrapper = new Bootstrapper(); 30 | 31 | /// 32 | /// Starts the application 33 | /// 34 | public static void Start() 35 | { 36 | DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); 37 | DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); 38 | Bootstrapper.Initialize(CreateKernel); 39 | } 40 | 41 | /// 42 | /// Stops the application. 43 | /// 44 | public static void Stop() 45 | { 46 | Bootstrapper.ShutDown(); 47 | } 48 | 49 | /// 50 | /// Creates the kernel that will manage your application. 51 | /// 52 | /// The created kernel. 53 | private static IKernel CreateKernel() 54 | { 55 | var kernel = new StandardKernel(); 56 | try 57 | { 58 | kernel.Bind>().ToMethod(ctx => () => new Bootstrapper().Kernel); 59 | kernel.Bind().To(); 60 | 61 | RegisterServices(kernel); 62 | return kernel; 63 | } 64 | catch 65 | { 66 | kernel.Dispose(); 67 | throw; 68 | } 69 | } 70 | 71 | /// 72 | /// Load your modules or register your services here! 73 | /// 74 | /// The kernel. 75 | private static void RegisterServices(IKernel kernel) 76 | { 77 | kernel.Bind().To().InRequestScope(); 78 | kernel.Bind(typeof(IDbRepository<>)).To(typeof(DbRepository<>)); 79 | 80 | kernel.Bind().To().InSingletonScope(); 81 | kernel.Bind().To().InSingletonScope(); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Source/Services/OnlineGames.Services.AiPortal/Uploads/LibraryValidators/SantaseLibraryValidator.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Services.AiPortal.Uploads.LibraryValidators 7 | { 8 | using System; 9 | using System.Linq; 10 | using System.Reflection; 11 | 12 | using Santase.Logic.GameMechanics; 13 | using Santase.Logic.Players; 14 | 15 | public class SantaseLibraryValidator : ILibraryValidator 16 | { 17 | public LibraryValidatorResult Validate(Assembly assembly) 18 | { 19 | var playerClasses = 20 | assembly.GetTypes() 21 | .Where(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(IPlayer).IsAssignableFrom(x)).ToList(); 22 | if (playerClasses.Count > 1) 23 | { 24 | return new LibraryValidatorResult("More than one public inheritant of IPlayer found."); 25 | } 26 | 27 | if (playerClasses.Count == 0) 28 | { 29 | return new LibraryValidatorResult("No public types that inherit IPlayer (or BasePlayer) found!"); 30 | } 31 | 32 | var playerClass = playerClasses[0]; 33 | IPlayer firstInstance; 34 | IPlayer secondInstance; 35 | try 36 | { 37 | // TODO: Time limit (if available use decorator from the library) 38 | // TODO: var sandbox = Sandbox.CreateSandbox(); 39 | // TODO: firstInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer; 40 | // TODO: secondInstance = sandbox.CreateInstanceFromAndUnwrap(playerClass.Assembly.FullName, playerClass.FullName) as IPlayer; 41 | firstInstance = Activator.CreateInstance(playerClass) as IPlayer; 42 | secondInstance = Activator.CreateInstance(playerClass) as IPlayer; 43 | } 44 | catch (Exception ex) 45 | { 46 | return new LibraryValidatorResult($"Creating instance of \"{playerClass.Name}\" failed: {ex.Message}"); 47 | } 48 | 49 | if (firstInstance == null || secondInstance == null) 50 | { 51 | return new LibraryValidatorResult($"Instance of \"{playerClass.Name}\" is null."); 52 | } 53 | 54 | try 55 | { 56 | var santaseGame = new SantaseGame(firstInstance, secondInstance); 57 | santaseGame.Start(); 58 | santaseGame = new SantaseGame(secondInstance, firstInstance); 59 | santaseGame.Start(); 60 | } 61 | catch (Exception ex) 62 | { 63 | return new LibraryValidatorResult($"Playing a new game between two instances of your player failed: {ex.Message}"); 64 | } 65 | 66 | return new LibraryValidatorResult(); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/CompetitionsController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System.Linq; 9 | using System.Web.Mvc; 10 | 11 | using AutoMapper.QueryableExtensions; 12 | 13 | using OnlineGames.Common; 14 | using OnlineGames.Data.Common; 15 | using OnlineGames.Data.Models; 16 | using OnlineGames.Services.AiPortal.Battles; 17 | using OnlineGames.Web.AiPortal.ViewModels.Competitions; 18 | 19 | public class CompetitionsController : BaseController 20 | { 21 | private readonly IDbRepository competitionsRepository; 22 | 23 | private readonly IDbRepository teamsRepository; 24 | 25 | private readonly IDbRepository battlesRepository; 26 | 27 | private readonly IBattlesGenerator battlesGenerator; 28 | 29 | public CompetitionsController( 30 | IDbRepository competitionsRepository, 31 | IDbRepository teamsRepository, 32 | IDbRepository battlesRepository, 33 | IBattlesGenerator battlesGenerator) 34 | { 35 | this.competitionsRepository = competitionsRepository; 36 | this.teamsRepository = teamsRepository; 37 | this.battlesRepository = battlesRepository; 38 | this.battlesGenerator = battlesGenerator; 39 | } 40 | 41 | [HttpGet] 42 | public ActionResult Info(int id) 43 | { 44 | var competition = 45 | this.competitionsRepository.All() 46 | .Where(x => x.IsActive && x.Id == id) 47 | .ProjectTo() 48 | .FirstOrDefault(); 49 | if (competition == null) 50 | { 51 | return this.HttpNotFound("Competition not found!"); 52 | } 53 | 54 | foreach (var team in competition.Teams) 55 | { 56 | team.UnfinishedBattles = 57 | this.battlesRepository.All() 58 | .Count(x => !x.IsFinished && (x.FirstTeamId == team.Id || x.SecondTeamId == team.Id)); 59 | } 60 | 61 | return this.View(competition); 62 | } 63 | 64 | [Authorize(Roles = GlobalConstants.AdministratorRoleName)] 65 | public ActionResult CreateBattles(int id) 66 | { 67 | var newBattles = this.battlesGenerator.GenerateBattles(this.teamsRepository, this.battlesRepository, id); 68 | this.TempData["Info"] = $"{newBattles} new battles created successfully!"; 69 | return this.RedirectToAction(nameof(this.Info), new { id }); 70 | } 71 | 72 | [Authorize(Roles = GlobalConstants.AdministratorRoleName)] 73 | public ActionResult RestartBattles(int id) 74 | { 75 | var restartedBattles = this.battlesGenerator.RestartBattlesForCompetition(this.battlesRepository, id); 76 | this.TempData["Info"] = $"{restartedBattles} battles restarted successfully!"; 77 | return this.RedirectToAction(nameof(this.Info), new { id }); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Source/OnlineGames.Common/OnlineGames.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8E6474C8-D25F-41B1-A7DE-4AC2F73C7D91} 8 | Library 9 | Properties 10 | OnlineGames.Common 11 | OnlineGames.Common 12 | v4.6 13 | 512 14 | 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | ..\Rules.ruleset 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | ..\Rules.ruleset 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | stylecop.json 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 72 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/Configuration.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Migrations 7 | { 8 | using System.Data.Entity.Migrations; 9 | using System.Linq; 10 | 11 | using OnlineGames.Common; 12 | using OnlineGames.Data.Models; 13 | 14 | public sealed class Configuration : DbMigrationsConfiguration 15 | { 16 | public Configuration() 17 | { 18 | this.AutomaticMigrationsEnabled = false; 19 | } 20 | 21 | protected override void Seed(AiPortalDbContext context) 22 | { 23 | if (!context.Roles.Any()) 24 | { 25 | this.SeedRoles(context); 26 | this.SeedCompetitions(context); 27 | 28 | context.SaveChanges(); 29 | } 30 | } 31 | 32 | private void SeedRoles(AiPortalDbContext context) 33 | { 34 | var role = new Role { Name = GlobalConstants.AdministratorRoleName }; 35 | context.Roles.Add(role); 36 | } 37 | 38 | private void SeedCompetitions(AiPortalDbContext context) 39 | { 40 | context.Competitions.Add( 41 | new Competition 42 | { 43 | Name = "Santase (Сантасе) AI", 44 | Description = @"

Santase (known as 66, Сантасе, Sixty-six or Sechsundsechzig) is a well-known card game in Bulgaria and also played in Germany.

45 |

It is a fast 6-card game for 2 players played with a deck of 24 cards consisting of the Ace, Ten, King, Queen, Jack and Nine.

46 |

The game is named 66 because the objective of each hand is to be the first to collect 66 card points in tricks and melds.

", 47 | IsActive = true, 48 | MinimumParticipants = 2, 49 | MaximumParticipants = 3, 50 | LibraryValidatorClassName = "OnlineGames.Services.AiPortal.Uploads.LibraryValidators.SantaseLibraryValidator", 51 | GamesExecutorClassName = "OnlineGames.Workers.BattlesSimulator.GamesExecutors.SantaseGamesExecutor", 52 | }); 53 | context.Competitions.Add( 54 | new Competition 55 | { 56 | Name = "Texas Hold'em AI", 57 | Description = @"

As in most forms of poker, Texas Hold’em uses a standard 52-card deck that is shuffled before every hand.

58 |

Each player starts with two hole cards. There are three rounds of community cards. These are dealt face up, for every player to use, with betting after each round.

59 |

The best 5-card hand using any combination of the five community cards and two hole cards wins.

", 60 | IsActive = true, 61 | MinimumParticipants = 2, 62 | MaximumParticipants = 3, 63 | LibraryValidatorClassName = "OnlineGames.Services.AiPortal.Uploads.LibraryValidators.TexasHoldemLibraryValidator", 64 | GamesExecutorClassName = "OnlineGames.Workers.BattlesSimulator.GamesExecutors.TexasHoldemGamesExecutor", 65 | }); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data/Migrations/201511282136457_Battles.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Data.Migrations 7 | { 8 | using System.Data.Entity.Migrations; 9 | 10 | public partial class Battles : DbMigration 11 | { 12 | public override void Up() 13 | { 14 | this.CreateTable( 15 | "dbo.Battles", 16 | c => new 17 | { 18 | Id = c.Int(nullable: false, identity: true), 19 | FirstTeamId = c.Int(nullable: false), 20 | SecondTeamId = c.Int(nullable: false), 21 | IsFinished = c.Boolean(nullable: false), 22 | Comment = c.String(), 23 | CreatedOn = c.DateTime(nullable: false), 24 | ModifiedOn = c.DateTime(), 25 | IsDeleted = c.Boolean(nullable: false), 26 | DeletedOn = c.DateTime(), 27 | }) 28 | .PrimaryKey(t => t.Id) 29 | .ForeignKey("dbo.Teams", t => t.FirstTeamId, cascadeDelete: false) 30 | .ForeignKey("dbo.Teams", t => t.SecondTeamId, cascadeDelete: false) 31 | .Index(t => t.FirstTeamId) 32 | .Index(t => t.SecondTeamId) 33 | .Index(t => t.IsDeleted); 34 | 35 | this.CreateTable( 36 | "dbo.BattleGameResults", 37 | c => new 38 | { 39 | Id = c.Int(nullable: false, identity: true), 40 | BattleId = c.Int(nullable: false), 41 | Report = c.String(), 42 | BattleGameWinner = c.Int(nullable: false), 43 | CreatedOn = c.DateTime(nullable: false), 44 | ModifiedOn = c.DateTime(), 45 | IsDeleted = c.Boolean(nullable: false), 46 | DeletedOn = c.DateTime(), 47 | }) 48 | .PrimaryKey(t => t.Id) 49 | .ForeignKey("dbo.Battles", t => t.BattleId, cascadeDelete: true) 50 | .Index(t => t.BattleId) 51 | .Index(t => t.IsDeleted); 52 | 53 | this.AddColumn("dbo.Competitions", "GamesToPlayForEachBattle", c => c.Int(nullable: false)); 54 | this.AddColumn("dbo.Teams", "Points", c => c.Int(nullable: false)); 55 | } 56 | 57 | public override void Down() 58 | { 59 | this.DropForeignKey("dbo.Battles", "SecondTeamId", "dbo.Teams"); 60 | this.DropForeignKey("dbo.Battles", "FirstTeamId", "dbo.Teams"); 61 | this.DropForeignKey("dbo.BattleGameResults", "BattleId", "dbo.Battles"); 62 | this.DropIndex("dbo.BattleGameResults", new[] { "IsDeleted" }); 63 | this.DropIndex("dbo.BattleGameResults", new[] { "BattleId" }); 64 | this.DropIndex("dbo.Battles", new[] { "IsDeleted" }); 65 | this.DropIndex("dbo.Battles", new[] { "SecondTeamId" }); 66 | this.DropIndex("dbo.Battles", new[] { "FirstTeamId" }); 67 | this.DropColumn("dbo.Teams", "Points"); 68 | this.DropColumn("dbo.Competitions", "GamesToPlayForEachBattle"); 69 | this.DropTable("dbo.BattleGameResults"); 70 | this.DropTable("dbo.Battles"); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Views/Teams/Info.cshtml: -------------------------------------------------------------------------------- 1 | @using OnlineGames.Web.AiPortal.Infrastructure 2 | @model OnlineGames.Web.AiPortal.ViewModels.Teams.TeamInfoViewModel 3 | @{ 4 | var currentUserIsPartOfTheTeam = Model.TeamMembers.Any(x => string.Equals(x.UserName, User.Identity.Name, StringComparison.OrdinalIgnoreCase)); 5 | ViewBag.Title = $"Team {Model.Name} ({Model.Points} points)"; 6 | } 7 | 8 |

9 | @ViewBag.Title 10 | @if (currentUserIsPartOfTheTeam) 11 | { 12 | Upload AI Library 13 | } 14 |

15 | 16 |
17 | 18 | 27 | 28 |
29 | 30 |

Uploads

31 | @if (Model.Uploads.Any()) 32 | { 33 |

Only the last uploaded file will be used for AI battles.

34 | 35 | 36 | 37 | 38 | 39 | @if (User.IsAdmin() || currentUserIsPartOfTheTeam) 40 | { 41 | 42 | } 43 | 44 | @foreach (var upload in Model.Uploads.OrderByDescending(x => x.Id)) 45 | { 46 | 47 | 48 | 49 | 50 | @if (User.IsAdmin() || currentUserIsPartOfTheTeam) 51 | { 52 | 53 | } 54 | 55 | } 56 |
#File nameUploaded onDownload
@upload.Id@upload.FileName@upload.CreatedOn
57 | } 58 | else 59 | { 60 |

No uploads for this team :(

61 | } 62 | 63 |
64 | 65 |

Battles

66 | @if (Model.Battles.Any()) 67 | { 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | @foreach (var battle in Model.Battles.OrderBy(x => x.OpponentTeam)) 77 | { 78 | var rowClass = ""; 79 | if (!battle.IsFinished) 80 | { 81 | rowClass = "active"; 82 | } 83 | 84 | 85 | 86 | 87 | 99 | 100 | 101 | } 102 |
Opponent team@Model.NameOpponent pointsCommentLast change
@battle.OpponentTeam@battle.TeamWins@battle.OpponentWins 88 | 89 | @if (!battle.IsFinished) 90 | { 91 | Battle is not finished, yet. 92 | } 93 | else 94 | { 95 | @battle.Comment 96 | } 97 | 98 | @battle.ModifiedOn
103 |

104 | Current sum of points: @Model.Battles.Sum(x => x.TeamWins)
105 | There might be a difference between the official team points and the current sum. This is due to still unfinished battles. 106 |

107 | } 108 | else 109 | { 110 |

No battles :(

111 | } 112 | -------------------------------------------------------------------------------- /Source/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | #*.pubxml 135 | #*.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | ~$* 157 | *~ 158 | *.dbmdl 159 | *.dbproj.schemaview 160 | *.pfx 161 | *.publishsettings 162 | node_modules/ 163 | bower_components/ 164 | 165 | # RIA/Silverlight projects 166 | Generated_Code/ 167 | 168 | # Backup & report files from converting an old project file 169 | # to a newer Visual Studio version. Backup files are not needed, 170 | # because we have git ;-) 171 | _UpgradeReport_Files/ 172 | Backup*/ 173 | UpgradeLog*.XML 174 | UpgradeLog*.htm 175 | 176 | # SQL Server files 177 | *.mdf 178 | *.ldf 179 | 180 | # Business Intelligence projects 181 | *.rdl.data 182 | *.bim.layout 183 | *.bim_*.settings 184 | 185 | # Microsoft Fakes 186 | FakesAssemblies/ 187 | 188 | # Node.js Tools for Visual Studio 189 | .ntvs_analysis.dat 190 | 191 | # Visual Studio 6 build log 192 | *.plg 193 | 194 | # Visual Studio 6 workspace options file 195 | *.opt 196 | -------------------------------------------------------------------------------- /Source/Workers/OnlineGames.Workers.BattlesSimulator/GamesExecutors/TexasHoldemPlayerDirector.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Workers.BattlesSimulator.GamesExecutors 7 | { 8 | using System; 9 | using System.Threading.Tasks; 10 | 11 | using TexasHoldem.Logic.Players; 12 | 13 | public class TexasHoldemPlayerDirector : PlayerDecorator 14 | { 15 | public TexasHoldemPlayerDirector(IPlayer player) 16 | : base(player) 17 | { 18 | } 19 | 20 | public int TimeOuts { get; private set; } 21 | 22 | public int Crashes { get; private set; } 23 | 24 | public string FirstCrash { get; private set; } 25 | 26 | public override string Name { get; } = Guid.NewGuid().ToString(); 27 | 28 | public override void StartGame(StartGameContext context) 29 | { 30 | this.TimeOuts = 0; 31 | this.Crashes = 0; 32 | this.FirstCrash = null; 33 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => base.StartGame(context)); 34 | } 35 | 36 | public override void StartRound(StartRoundContext context) 37 | { 38 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => base.StartRound(context)); 39 | } 40 | 41 | public override void StartHand(StartHandContext context) 42 | { 43 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => base.StartHand(context)); 44 | } 45 | 46 | public override PlayerAction GetTurn(GetTurnContext context) 47 | { 48 | try 49 | { 50 | PlayerAction playerAction = null; 51 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => playerAction = base.GetTurn(context)); 52 | if (playerAction != null) 53 | { 54 | return playerAction; 55 | } 56 | else 57 | { 58 | this.TimeOuts++; 59 | return PlayerAction.CheckOrCall(); 60 | } 61 | } 62 | catch (Exception ex) 63 | { 64 | this.Crashes++; 65 | if (this.FirstCrash == null) 66 | { 67 | this.FirstCrash = ex.ToString(); 68 | } 69 | 70 | return PlayerAction.CheckOrCall(); 71 | } 72 | } 73 | 74 | public override void EndHand(EndHandContext context) 75 | { 76 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => base.EndHand(context)); 77 | } 78 | 79 | public override void EndRound(EndRoundContext context) 80 | { 81 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => base.EndRound(context)); 82 | } 83 | 84 | public override void EndGame(EndGameContext context) 85 | { 86 | ExecuteWithTimeLimit(TimeSpan.FromMilliseconds(50), () => base.EndGame(context)); 87 | } 88 | 89 | private static void ExecuteWithTimeLimit(TimeSpan timeSpan, Action codeBlock) 90 | { 91 | // TODO: memory limit? 92 | try 93 | { 94 | var task = Task.Factory.StartNew(codeBlock); 95 | task.Wait(timeSpan); 96 | //// return task.IsCompleted; 97 | } 98 | catch (AggregateException ae) 99 | { 100 | if (ae.InnerExceptions != null && ae.InnerExceptions.Count > 0) 101 | { 102 | throw ae.InnerExceptions[0]; 103 | } 104 | else 105 | { 106 | throw; 107 | } 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Source/Rules.ruleset: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /Source/Data/OnlineGames.Data.Common/OnlineGames.Data.Common.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A4379059-F6BA-4E0D-B88D-B8E8C5D8EEF1} 8 | Library 9 | Properties 10 | OnlineGames.Data.Common 11 | OnlineGames.Data.Common 12 | v4.6 13 | 512 14 | 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | ..\..\Rules.ruleset 27 | 28 | 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | ..\..\Rules.ruleset 36 | 37 | 38 | 39 | ..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll 40 | True 41 | 42 | 43 | ..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll 44 | True 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | stylecop.json 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 87 | -------------------------------------------------------------------------------- /Source/Web/OnlineGames.Web.AiPortal/Controllers/AccountController.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Nikolay Kostov (Nikolay.IT). All Rights Reserved. 3 | // Licensed under the MIT License. See LICENSE in the project root for license information. 4 | // 5 | 6 | namespace OnlineGames.Web.AiPortal.Controllers 7 | { 8 | using System; 9 | using System.Linq; 10 | using System.Threading.Tasks; 11 | using System.Web; 12 | using System.Web.Mvc; 13 | using System.Web.Security; 14 | 15 | using Newtonsoft.Json; 16 | 17 | using OnlineGames.Common; 18 | using OnlineGames.Data.Common; 19 | using OnlineGames.Data.Models; 20 | using OnlineGames.Services.AiPortal; 21 | using OnlineGames.Web.AiPortal.Infrastructure; 22 | using OnlineGames.Web.AiPortal.ViewModels.Account; 23 | 24 | public class AccountController : BaseController 25 | { 26 | private readonly IDbRepository usersRepository; 27 | private readonly IDbRepository rolesRepository; 28 | 29 | public AccountController(IDbRepository usersRepository, IDbRepository rolesRepository) 30 | { 31 | this.usersRepository = usersRepository; 32 | this.rolesRepository = rolesRepository; 33 | } 34 | 35 | [HttpGet] 36 | public ActionResult LoginWithTelerikAcademy() 37 | { 38 | return this.View(); 39 | } 40 | 41 | [HttpPost] 42 | [ValidateAntiForgeryToken] 43 | public async Task LoginWithTelerikAcademy(ExternalLoginViewModel model, string returnUrl) 44 | { 45 | if (!this.ModelState.IsValid) 46 | { 47 | return this.View(model); 48 | } 49 | 50 | var remoteResult = await new RemoteDataService().Login(model.UserName, model.Password); 51 | if (remoteResult == null || !remoteResult.IsValid) 52 | { 53 | this.ModelState.AddModelError(string.Empty, "Invalid login attempt."); 54 | return this.View(model); 55 | } 56 | 57 | var databaseUser = this.usersRepository.All().FirstOrDefault(x => x.UserName == remoteResult.UserName); 58 | if (databaseUser == null) 59 | { 60 | databaseUser = new User 61 | { 62 | UserName = remoteResult.UserName, 63 | AvatarUrl = remoteResult.SmallAvatarUrl, 64 | Provider = UserProvider.TelerikAcademyUser, 65 | }; 66 | if (remoteResult.IsAdmin) 67 | { 68 | var adminRole = 69 | this.rolesRepository.All().FirstOrDefault(x => x.Name == GlobalConstants.AdministratorRoleName); 70 | databaseUser.Roles.Add(adminRole); 71 | } 72 | 73 | this.usersRepository.Add(databaseUser); 74 | this.usersRepository.Save(); 75 | } 76 | 77 | var roles = databaseUser.Roles.Select(x => x.Name).ToList(); 78 | var userDataObject = new AiPortalUserData(databaseUser.UserName, roles); 79 | 80 | var userDataAsString = JsonConvert.SerializeObject(userDataObject); 81 | var authTicket = new FormsAuthenticationTicket( 82 | 1, 83 | model.UserName, 84 | DateTime.Now, 85 | DateTime.Now.AddDays(1), // Expire after 86 | false, 87 | userDataAsString); 88 | var encTicket = FormsAuthentication.Encrypt(authTicket); 89 | var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); 90 | this.Response.Cookies.Add(cookie); 91 | 92 | return this.RedirectToLocal(returnUrl); 93 | } 94 | 95 | [HttpPost] 96 | [ValidateAntiForgeryToken] 97 | public ActionResult LogOff() 98 | { 99 | FormsAuthentication.SignOut(); 100 | return this.RedirectToAction("Index", "Home"); 101 | } 102 | 103 | private ActionResult RedirectToLocal(string returnUrl) 104 | { 105 | if (this.Url.IsLocalUrl(returnUrl)) 106 | { 107 | return this.Redirect(returnUrl); 108 | } 109 | 110 | return this.RedirectToAction("Index", "Home"); 111 | } 112 | } 113 | } 114 | --------------------------------------------------------------------------------