Skip to content

Commit

Permalink
#260 SIQuester incorrectly handles files with the same names when joi…
Browse files Browse the repository at this point in the history
…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
VladimirKhil committed Jan 6, 2025
1 parent 214c67f commit 1b7dba9
Show file tree
Hide file tree
Showing 64 changed files with 441 additions and 763 deletions.
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<PropertyGroup>
<Authors>Vladimir Khil</Authors>
<Company>Khil-soft</Company>
<Copyright>Copyright © Khil-soft 2002 - 2024</Copyright>
<SIGameVersion>7.13.2</SIGameVersion>
<SIQuesterVersion>6.2.2</SIQuesterVersion>
<SImulatorVersion>3.1.0</SImulatorVersion>
<Copyright>Copyright © Khil-soft 2002 - 2025</Copyright>
<SIGameVersion>7.13.3</SIGameVersion>
<SIQuesterVersion>6.2.3</SIQuesterVersion>
<SImulatorVersion>3.1.1</SImulatorVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
13 changes: 0 additions & 13 deletions src/Common/SIUI.ViewModel/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@ public double QuestionLineSpacing
set { if (Math.Abs(_questionLineSpacing - value) > double.Epsilon) { _questionLineSpacing = value; OnPropertyChanged(); } }
}

private bool _showScore = false;

[DefaultValue(false)]
[XmlAttribute]
[DataMember]
[Obsolete]
public bool ShowScore
{
get => _showScore;
set { if (_showScore != value) { _showScore = value; OnPropertyChanged(); } }
}

private bool _animate3D = true;

[DefaultValue(true)]
Expand Down Expand Up @@ -217,7 +205,6 @@ public void Initialize(Settings uiSettings)
TableBackColorString = uiSettings._tableBackColorString;
TableGridColorString = uiSettings.TableGridColorString;
AnswererColorString = uiSettings.AnswererColorString;
ShowScore = uiSettings._showScore;
KeyboardControl = uiSettings._keyboardControl;
Animate3D = uiSettings._animate3D;
LogoUri = uiSettings._logoUri;
Expand Down
1 change: 0 additions & 1 deletion src/Common/SIUI.ViewModel/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public void Initialize(Settings uiSettings)
_model.TableBackColorString = uiSettings.TableBackColorString;
_model.TableGridColorString = uiSettings.TableGridColorString;
_model.AnswererColorString = uiSettings.AnswererColorString;
_model.ShowScore = uiSettings.ShowScore;
_model.KeyboardControl = uiSettings.KeyboardControl;
_model.Animate3D = uiSettings.Animate3D;
_model.LogoUri = uiSettings.LogoUri;
Expand Down
9 changes: 8 additions & 1 deletion src/SICore/SICore/Clients/Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3616,7 +3616,14 @@ private GamePersonAccount CreateNewComputerShowman(ComputerAccount account)
var showmanClient = Network.Clients.Client.Create(newAccount.Name, _client.Node);
var data = new ViewerData(ClientData.Host);
var actions = new ViewerActions(showmanClient, LO);
var logic = new ViewerComputerLogic(data, actions, account, new Intelligence(account), GameRole.Showman);

var logic = new ViewerComputerLogic(
data,
actions,
account,
new Intelligence(account),
GameRole.Showman);

var showman = new Showman(showmanClient, account, false, logic, actions, LO, data);

OnInfo(newAccount.Name);
Expand Down
4 changes: 2 additions & 2 deletions src/SICore/SICore/Clients/Other/PersonAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
namespace SICore;

/// <summary>
/// Defines main game person.
/// Defines main game person (player or showman).
/// </summary>
public class PersonAccount : ViewerAccount
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private bool _ready = false;

/// <summary>
/// Готов ли участник к игре
/// Is the person ready to start the game.
/// </summary>
[DefaultValue(false)]
public bool Ready
Expand Down
5 changes: 4 additions & 1 deletion src/SICore/SICore/Clients/Other/PlayerAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SICore;

/// <summary>
/// Информация об игроке во время игры
/// Defines player info.
/// </summary>
public sealed class PlayerAccount : PersonAccount
{
Expand All @@ -16,6 +16,9 @@ public sealed class PlayerAccount : PersonAccount

private bool _canBeSelected = false;

/// <summary>
/// Can the player be selected.
/// </summary>
public bool CanBeSelected
{
get => _canBeSelected;
Expand Down
4 changes: 2 additions & 2 deletions src/SICore/SICore/Clients/Player/PlayerComputerLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class PlayerComputerLogic
{
private const int DefaultThemeQuestionCount = 5;

private readonly IIntelligence _intelligence;
private readonly IPlayerIntelligence _intelligence;
private readonly ComputerAccount _account;
private readonly ViewerActions _viewerActions;
private readonly ViewerData _data;
Expand Down Expand Up @@ -62,7 +62,7 @@ internal sealed class PlayerComputerLogic
/// <summary>
/// Initializes a new instance of the <see cref="PlayerComputerLogic"/> class.
/// </summary>
public PlayerComputerLogic(ViewerData data, ComputerAccount account, IIntelligence intelligence, ViewerActions viewerActions, TimerInfo[] timerInfos)
public PlayerComputerLogic(ViewerData data, ComputerAccount account, IPlayerIntelligence intelligence, ViewerActions viewerActions, TimerInfo[] timerInfos)
{
Ensure.That(account).IsNotNull();

Expand Down
107 changes: 107 additions & 0 deletions src/SICore/SICore/Clients/Showman/ShowmanComputerController.cs
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,
}
}
82 changes: 0 additions & 82 deletions src/SICore/SICore/Clients/Showman/ShowmanComputerLogic.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/SICore/SICore/Clients/Showman/ShowmanTasks.cs

This file was deleted.

11 changes: 8 additions & 3 deletions src/SICore/SICore/Clients/Viewer/ViewerComputerLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ internal class ViewerComputerLogic : Logic<ViewerData>, IViewerLogic
public bool CanSwitchType => false;

private readonly PlayerComputerLogic _player;
private readonly ShowmanComputerLogic _showman;
private readonly ShowmanComputerController _showman;

private readonly TimerInfo[] _timersInfo = new TimerInfo[] { new(), new(), new() };

private readonly GameRole _role;

internal ViewerComputerLogic(ViewerData data, ViewerActions viewerActions, ComputerAccount computerAccount, IIntelligence intelligence, GameRole role)
internal ViewerComputerLogic(
ViewerData data,
ViewerActions viewerActions,
ComputerAccount computerAccount,
IIntelligence intelligence,
GameRole role)
: base(data)
{
_viewerActions = viewerActions;
_role = role;

_player = new PlayerComputerLogic(data, computerAccount, intelligence, viewerActions, _timersInfo);
_showman = new ShowmanComputerLogic(data, viewerActions);
_showman = new ShowmanComputerController(data, viewerActions, intelligence);
}

public void IsRight(bool voteForRight, string answer)
Expand Down
17 changes: 2 additions & 15 deletions src/SICore/SICore/Contracts/IIntelligence.cs
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 { }
19 changes: 19 additions & 0 deletions src/SICore/SICore/Contracts/IPlayerIntelligence.cs
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);
}
Loading

0 comments on commit 1b7dba9

Please sign in to comment.