public KnowledgeBase(int BoardWidth, int BoardHeight, int WumpusCount, int HoleCount, bool Breeze, bool Stench, bool Glitter) { width = BoardWidth; height = BoardHeight; AgentPosition = new Position(0, 0, width, height); WIC = new WorldImageContainer(width, height, WumpusCount, HoleCount); WIC.SetExplored(0, 0, Breeze, Stench, Glitter); }
public void Reset( int Rows, int Columns, int WumpusCount, int HoleCount) { this.SuspendLayout(); this.Controls.Clear(); rows = Rows; columns = Columns; wumpusCount = WumpusCount; holeCount = HoleCount; AgentPosition = new Position(0, 0, rows, columns); AgentAlive = true; GoldFound = false; if (rows < 1 || columns < 1 || (Rows == 1 && Columns == 1)) throw new ArgumentOutOfRangeException(); if (rows * columns < 2 + wumpusCount + holeCount) throw new ArgumentException(); Squares = new WumpusWorldSquare[rows, columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { WumpusWorldSquare Sq = new WumpusWorldSquare(); Sq.MouseDown += new MouseEventHandler(this.SquareMouseDown); Squares[i, j] = Sq; this.Controls.Add(Sq); } } System.Random r = new Random(); int x, y, fields; //Proizvoljan odabir položaja blaga int Number = r.Next() % (rows * columns - 1) + 1; Squares[Number % rows, Number / rows].Glitter = true; //Postavljanje Wumpusa na različita mjesta fields = rows * columns - 2; for (int i = 1; i < rows * columns&& WumpusCount > 0; i++) { x = i % rows; y = i / rows; if (Squares[x, y].Glitter) continue; Number = r.Next() % (fields); fields--; if (Number < WumpusCount) { Squares[x, y].IsWumpus = true; //Postavljanje zadaha na odgovarajuća mjesta Squares[x, y].Stench = true; if (x > 0) Squares[x - 1, y].Stench = true; if (x < rows - 1) Squares[x + 1, y].Stench = true; if (y > 0) Squares[x, y - 1].Stench = true; if (y < columns - 1) Squares[x, y + 1].Stench = true; WumpusCount--; } } fields = rows * columns - 2 - wumpusCount; for (int i = 1; i < rows * columns && HoleCount > 0; i++) { x = i % rows; y = i / rows; if (Squares[x, y].Glitter || Squares[x, y].IsWumpus) continue; Number = r.Next() % (fields); fields--; if (Number < HoleCount) { Squares[x, y].IsHole = true; //Postavljanje propuha na odgovarajuća mjesta Squares[x, y].Breeze = true; if (x > 0) Squares[x - 1, y].Breeze = true; if (x < rows - 1) Squares[x + 1, y].Breeze = true; if (y > 0) Squares[x, y - 1].Breeze = true; if (y < columns - 1) Squares[x, y + 1].Breeze = true; HoleCount--; } } //Početno polje je poznato Squares[0, 0].Explored = true; Squares[0, 0].IsAgent = true; this.Size = new Size(this.Padding.Vertical + rows * squareDimension, this.Padding.Horizontal + columns * squareDimension); UpdateSquareSizes(); this.ResumeLayout(); this.PerformLayout(); }
public void AgentMove(Direction d) { if (!AgentAlive) return; if (GoldFound && AgentPosition.X == 0 && AgentPosition.Y == 0) return; moves++; this.SuspendLayout(); Position New = AgentPosition.Move(d); if (New == AgentPosition) return; Squares[AgentPosition.X, AgentPosition.Y].IsAgent = false; AgentPosition = New; WumpusWorldSquare Sq = Squares[AgentPosition.X, AgentPosition.Y]; Sq.Explored = true; Sq.IsAgent = true; this.Update(); this.ResumeLayout(false); this.PerformLayout(); if (Sq.IsHole || Sq.IsWumpus) { AgentAlive = false; this.OnGameEnded(new GameEndedEventArgs(false)); } if (Sq.Glitter && !GoldFound) { GoldFound = true; this.OnGoldFound(EventArgs.Empty); } if (AgentPosition.X == 0 && AgentPosition.Y == 0 && GoldFound) this.OnGameEnded(new GameEndedEventArgs(true)); this.OnAgentMoved(new AgentMovedEventArgs(d, AgentPosition.X, AgentPosition.Y)); }
public void Move(Direction dir, bool Breeze, bool Stench, bool Glitter) { AgentPosition = AgentPosition.Move(dir); WIC.SetExplored(AgentPosition.X, AgentPosition.Y, Breeze, Stench, Glitter); }