-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#260 SIQuester incorrectly handles files with the same names when joi…
…ning two packages Expose IShowmanIntelligence interface. Add OralText option to SImulator. Remove legacy web buttons from SImulator. Fix small errors. Provide link for item with missing files in statistics view in SIQuester. Update media links after media renaming in SIQuester.
- Loading branch information
1 parent
214c67f
commit 1b7dba9
Showing
64 changed files
with
441 additions
and
763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/SICore/SICore/Clients/Showman/ShowmanComputerController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using SICore.Contracts; | ||
|
||
namespace SICore; | ||
|
||
/// <summary> | ||
/// Defines a showman bot controller. | ||
/// </summary> | ||
internal sealed class ShowmanComputerController | ||
{ | ||
private readonly ViewerActions _viewerActions; | ||
private readonly ViewerData _data; | ||
private readonly IShowmanIntelligence _intelligence; | ||
|
||
public ShowmanComputerController(ViewerData data, ViewerActions viewerActions, IShowmanIntelligence intelligence) | ||
{ | ||
_viewerActions = viewerActions; | ||
_data = data; | ||
_intelligence = intelligence; | ||
} | ||
|
||
private async void ScheduleExecution(ShowmanTasks task, double taskTime, object? arg = null) | ||
{ | ||
await Task.Delay((int)taskTime * 100); | ||
|
||
try | ||
{ | ||
ExecuteTask(task, arg); | ||
} | ||
catch (Exception exc) | ||
{ | ||
_data.SystemLog.AppendFormat("Execution error: {0}", exc.ToString()).AppendLine(); | ||
} | ||
} | ||
|
||
private void ExecuteTask(ShowmanTasks task, object? arg) | ||
{ | ||
switch (task) | ||
{ | ||
case ShowmanTasks.Ready: | ||
OnReady(); | ||
break; | ||
|
||
case ShowmanTasks.SelectPlayer: | ||
OnSelectPlayer(); | ||
break; | ||
|
||
case ShowmanTasks.ValidateAnswer: | ||
OnValidateAnswer((string?)arg); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
private void OnReady() => _viewerActions.SendMessage(Messages.Ready); | ||
|
||
private void OnSelectPlayer() | ||
{ | ||
var availablePlayerCount = _data.Players.Count(p => p.CanBeSelected); | ||
var selectedIndex = Random.Shared.Next(availablePlayerCount); | ||
var currentIndex = 0; | ||
|
||
for (var i = 0; i < _data.Players.Count; i++) | ||
{ | ||
if (_data.Players[i].CanBeSelected) | ||
{ | ||
if (currentIndex == selectedIndex) | ||
{ | ||
_viewerActions.SendMessage(Messages.SelectPlayer, i.ToString()); | ||
break; | ||
} | ||
|
||
currentIndex++; | ||
} | ||
} | ||
} | ||
|
||
private void OnValidateAnswer(string? answer) | ||
{ | ||
var isRight = ValidateAnswerCore(answer); | ||
_viewerActions.SendMessage(Messages.IsRight, isRight ? "+" : "-"); | ||
} | ||
|
||
private bool ValidateAnswerCore(string? answer) | ||
{ | ||
if (string.IsNullOrEmpty(answer)) | ||
{ | ||
return false; | ||
} | ||
|
||
return _intelligence.ValidateAnswer(answer, _data.PersonDataExtensions.Right, _data.PersonDataExtensions.Wrong); | ||
} | ||
|
||
public void SelectPlayer() => ScheduleExecution(ShowmanTasks.SelectPlayer, 10 + Random.Shared.Next(10)); | ||
|
||
public void IsRight(string answer) => ScheduleExecution(ShowmanTasks.ValidateAnswer, 10 + Random.Shared.Next(10), answer); | ||
|
||
public void OnInitialized() => ScheduleExecution(ShowmanTasks.Ready, 10); | ||
|
||
private enum ShowmanTasks | ||
{ | ||
Ready, | ||
ValidateAnswer, | ||
SelectPlayer, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,6 @@ | ||
using SIUI.Model; | ||
|
||
namespace SICore.Contracts; | ||
namespace SICore.Contracts; | ||
|
||
/// <summary> | ||
/// Defines an intelligence behavior for player and showman. | ||
/// </summary> | ||
internal interface IIntelligence | ||
{ | ||
/// <summary> | ||
/// Selects a question on game table. | ||
/// </summary> | ||
(int themeIndex, int questionIndex) SelectQuestion( | ||
List<ThemeInfo> table, | ||
(int ThemeIndex, int QuestionIndex) previousSelection, | ||
int currentScore, | ||
int bestOpponentScore, | ||
int roundPassedTimePercentage); | ||
} | ||
internal interface IIntelligence : IPlayerIntelligence, IShowmanIntelligence { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using SIUI.Model; | ||
|
||
namespace SICore.Contracts; | ||
|
||
/// <summary> | ||
/// Defines an intelligence behavior for player. | ||
/// </summary> | ||
internal interface IPlayerIntelligence | ||
{ | ||
/// <summary> | ||
/// Selects a question on game table. | ||
/// </summary> | ||
(int themeIndex, int questionIndex) SelectQuestion( | ||
List<ThemeInfo> table, | ||
(int ThemeIndex, int QuestionIndex) previousSelection, | ||
int currentScore, | ||
int bestOpponentScore, | ||
int roundPassedTimePercentage); | ||
} |
Oops, something went wrong.